Skip to content

Instantly share code, notes, and snippets.

@BlackScorp
Created March 8, 2016 21:29
Show Gist options
  • Save BlackScorp/a67b278c365a18d24435 to your computer and use it in GitHub Desktop.
Save BlackScorp/a67b278c365a18d24435 to your computer and use it in GitHub Desktop.
<?php
interface BarRepository{
public function findByFoo($foo) : BarEntity[]
}
class BarRepositoryImplementation implements BarRepository{
public function findByFoo($foo): BarEntity[]
{
//Some SQL or other things
if($noResults){ //case 1
throw new NotFoundException();
}
$collection = [new NullBarEntity()];
if($noResults){ //case 2
return $collection;
}
if($noResults){
return []; //fatal error, wrong return value
}
if($noResults){
return null; //fatal error, wrong return value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment