You are here

class MagicCallPatch in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/MagicCallPatch.php \Prophecy\Doubler\ClassPatch\MagicCallPatch

Discover Magical API using "@method" PHPDoc format.

@author Thomas Tourlourat <thomas@tourlourat.com>

Hierarchy

Expanded class hierarchy of MagicCallPatch

File

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

Namespace

Prophecy\Doubler\ClassPatch
View source
class MagicCallPatch implements ClassPatchInterface {

  /**
   * Support any class
   *
   * @param ClassNode $node
   *
   * @return boolean
   */
  public function supports(ClassNode $node) {
    return true;
  }

  /**
   * Discover Magical API
   *
   * @param ClassNode $node
   */
  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);
      }
    }
  }

  /**
   * Returns patch priority, which determines when patch will be applied.
   *
   * @return integer Priority number (higher - earlier)
   */
  public function getPriority() {
    return 50;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MagicCallPatch::apply public function Discover Magical API Overrides ClassPatchInterface::apply
MagicCallPatch::getPriority public function Returns patch priority, which determines when patch will be applied. Overrides ClassPatchInterface::getPriority
MagicCallPatch::supports public function Support any class Overrides ClassPatchInterface::supports