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\ClassPatchCode
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();
}
}
}