PhpDeal\Contract\Fetcher\ParentClass\MethodConditionWithInheritDocFetcher::getConditions PHP Method

getConditions() public method

Fetches conditions from all parent method prototypes recursively
public getConditions ( ReflectionClass $class, string $methodName ) : array
$class ReflectionClass
$methodName string
return array
    public function getConditions(ReflectionClass $class, $methodName)
    {
        $annotations = [];
        $parentMethods = [];
        while (preg_match('/\\@inheritdoc/i', $class->getMethod($methodName)->getDocComment()) && ($class = $class->getParentClass()) && $class->hasMethod($methodName)) {
            $parentMethods[] = $class->getMethod($methodName);
        }
        foreach ($parentMethods as $parentMethod) {
            $annotations = array_merge($annotations, $this->annotationReader->getMethodAnnotations($parentMethod));
        }
        $contracts = $this->filterContractAnnotation($annotations);
        return $contracts;
    }

Usage Example

 /**
  * @param MethodInvocation $invocation
  * @return array
  */
 private function fetchParentsContracts(MethodInvocation $invocation)
 {
     return $this->methodConditionFetcher->getConditions($invocation->getMethod()->getDeclaringClass(), $invocation->getMethod()->name);
 }
MethodConditionWithInheritDocFetcher