You are here

public function MagicCallPatch::apply in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/MagicCallPatch.php \Prophecy\Doubler\ClassPatch\MagicCallPatch::apply()

Discover Magical API

Parameters

ClassNode $node:

Overrides ClassPatchInterface::apply

File

vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/MagicCallPatch.php, line 42

Class

MagicCallPatch
Discover Magical API using "@method" PHPDoc format.

Namespace

Prophecy\Doubler\ClassPatch

Code

public function apply(ClassNode $node) {
  $parentClass = $node
    ->getParentClass();
  $reflectionClass = new \ReflectionClass($parentClass);
  $phpdoc = new DocBlock($reflectionClass
    ->getDocComment());
  $tagList = $phpdoc
    ->getTagsByName('method');
  foreach ($tagList as $tag) {
    $methodName = $tag
      ->getMethodName();
    if (!$reflectionClass
      ->hasMethod($methodName)) {
      $methodNode = new MethodNode($tag
        ->getMethodName());
      $methodNode
        ->setStatic($tag
        ->isStatic());
      $node
        ->addMethod($methodNode);
    }
  }
}