Zend\Code\Scanner\ClassScanner::getMethod PHP Method

getMethod() public method

Return a single method by given name or index of info
public getMethod ( string | integer $methodNameOrInfoIndex ) : Zend\Code\Scanner\MethodScanner
$methodNameOrInfoIndex string | integer
return Zend\Code\Scanner\MethodScanner
    public function getMethod($methodNameOrInfoIndex)
    {
        $this->scan();
        if (is_int($methodNameOrInfoIndex)) {
            $info = $this->infos[$methodNameOrInfoIndex];
            if ($info['type'] != 'method') {
                throw new Exception\InvalidArgumentException('Index of info offset is not about a method');
            }
            $methodNameOrInfoIndex = $info['name'];
        }
        $returnMethod = false;
        $methods = $this->getMethods();
        foreach ($methods as $method) {
            if ($method->getName() === $methodNameOrInfoIndex) {
                $returnMethod = $method;
                break;
            }
        }
        return $returnMethod;
    }

Usage Example

 /**
  * @param  int|string $methodNameOrInfoIndex
  * @return MethodScanner
  * @throws Exception\InvalidArgumentException
  */
 public function getMethod($methodNameOrInfoIndex)
 {
     if ($this->classScanner->hasMethod($methodNameOrInfoIndex)) {
         return $this->classScanner->getMethod($methodNameOrInfoIndex);
     }
     foreach ($this->parentClassScanners as $pClassScanner) {
         if ($pClassScanner->hasMethod($methodNameOrInfoIndex)) {
             return $pClassScanner->getMethod($methodNameOrInfoIndex);
         }
     }
     throw new Exception\InvalidArgumentException(sprintf('Method %s not found in %s', $methodNameOrInfoIndex, $this->classScanner->getName()));
 }
All Usage Examples Of Zend\Code\Scanner\ClassScanner::getMethod