Skip to content

Commit

Permalink
Reduced code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Apr 11, 2015
1 parent 11f2f01 commit fc98eeb
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Reflection/ClassPropertyReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public function getGetter($classNamespace, $propertyName)
'has'.ucfirst($propertyName),
);

foreach ($getterMethods as $method) {
if (method_exists($classNamespace, $method)) {
return $method;
}
}
return $this->getFirstExistingMethod($classNamespace, $getterMethods);
}

/**
Expand All @@ -56,7 +52,21 @@ public function getSetter($classNamespace, $propertyName)
$propertyName,
);

foreach ($setterMethods as $method) {
return $this->getFirstExistingMethod($classNamespace, $setterMethods);
}

/**
* Returns the name of the first method that exist for the given class, or
* null if none of the given methods exist.
*
* @param string $classNamespace
* @param array $methods
*
* @return string|null
*/
private function getFirstExistingMethod($classNamespace, array $methods)
{
foreach ($methods as $method) {
if (method_exists($classNamespace, $method)) {
return $method;
}
Expand Down

0 comments on commit fc98eeb

Please sign in to comment.