Many times i find this redundant:
$found = $repo->findOneByCode($code);
$zone = isset($found) ? $found : new Zone();
Can anyone suggest a better way, similar to (not working):
$zone = $repo->findOneByCode($code) || new Zone();
EDIT: i can’t modify Zone and findOneByCode as they are auto-generated classes and function by Doctrine ORM.
If you’re using >= PHP 5.3
otherwise maybe this is better? (still a bit ugly)…
Assuming on failure,
$repo->findOneByCode()returns a falsy value…