Skip to content

Instantly share code, notes, and snippets.

@schmittjoh
Last active August 29, 2015 13:56
Show Gist options
  • Save schmittjoh/9308549 to your computer and use it in GitHub Desktop.
Save schmittjoh/9308549 to your computer and use it in GitHub Desktop.
Example for how the same array is re-validated multiple times instead of validating it once/keeping track of its types.
<?php
class MyClass
{
public function doSomething(Foo[] $array) { // First check here.
if ($this->hasSomeElement($array)) {
$this->doSomethingBranch1($array);
} else {
$this->doSomethingBranch2($array);
}
}
private function hasSomeElement(Foo[] $array) { // Second validation here (unnecessary)
foreach ($array as $v) {
if ($v->isTrue()) {
return true;
}
}
return false;
}
private function doSomethingBranch1(Foo[] $array) { // Third validation here (unnecessary)
// ...
}
private function doSomethingBranch2(Foo[] $array) { // Another validation here (unnecessary)
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment