Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MagicCallPatch.php

function MagicCallPatch::apply

Discover Magical API

Parameters

ClassNode $node:

Overrides ClassPatchInterface::apply

File

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

Class

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

Namespace

Prophecy\Doubler\ClassPatch

Code

public function apply(ClassNode $node) {
    $types = array_filter($node->getInterfaces(), function ($interface) {
        return 0 !== strpos($interface, 'Prophecy\\');
    });
    $types[] = $node->getParentClass();
    foreach ($types as $type) {
        $reflectionClass = new \ReflectionClass($type);
        while ($reflectionClass) {
            $tagList = $this->tagRetriever
                ->getTagList($reflectionClass);
            foreach ($tagList as $tag) {
                $methodName = $tag->getMethodName();
                if (empty($methodName)) {
                    continue;
                }
                if (!$reflectionClass->hasMethod($methodName)) {
                    $methodNode = new MethodNode($methodName);
                    // only magic methods can have a contract that needs to be enforced
                    if (in_array($methodName, self::MAGIC_METHODS_WITH_ARGUMENTS)) {
                        if (method_exists($tag, 'getParameters')) {
                            // Reflection Docblock 5.4.0+.
                            foreach ($tag->getParameters() as $argument) {
                                $argumentNode = new ArgumentNode($argument->getName());
                                $methodNode->addArgument($argumentNode);
                            }
                        }
                        else {
                            // Reflection Docblock < 5.4.0.
                            foreach ($tag->getArguments() as $argument) {
                                $argumentNode = new ArgumentNode($argument['name']);
                                $methodNode->addArgument($argumentNode);
                            }
                        }
                    }
                    $methodNode->setStatic($tag->isStatic());
                    $node->addMethod($methodNode);
                }
            }
            $reflectionClass = $reflectionClass->getParentClass();
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal