-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathMethodReflectionFactory.php
More file actions
97 lines (87 loc) · 3.33 KB
/
MethodReflectionFactory.php
File metadata and controls
97 lines (87 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php declare(strict_types = 1);
namespace Weebly\PHPStan\Laravel;
use PHPStan\Broker\Broker;
use PHPStan\PhpDoc\PhpDocBlock;
use PHPStan\PhpDoc\Tag\ParamTag;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\Php\PhpMethodReflectionFactory;
use PHPStan\Type\FileTypeMapper;
use PHPStan\Type\Type;
final class MethodReflectionFactory
{
/**
* @var \PHPStan\Reflection\Php\PhpMethodReflectionFactory
*/
private $methodReflectionFactory;
/**
* @var \PHPStan\Type\FileTypeMapper
*/
private $fileTypeMapper;
/**
* MethodReflectionFactory constructor.
*
* @param \PHPStan\Reflection\Php\PhpMethodReflectionFactory $methodReflectionFactory
* @param \PHPStan\Type\FileTypeMapper $fileTypeMapper
*/
public function __construct(PhpMethodReflectionFactory $methodReflectionFactory, FileTypeMapper $fileTypeMapper)
{
$this->methodReflectionFactory = $methodReflectionFactory;
$this->fileTypeMapper = $fileTypeMapper;
}
/**
* @param \PHPStan\Reflection\ClassReflection $classReflection
* @param \ReflectionMethod $methodReflection
* @param string|null $methodWrapper
*
* @return \PHPStan\Reflection\MethodReflection
*
* @throws \PHPStan\ShouldNotHappenException
*/
public function create(ClassReflection $classReflection, \ReflectionMethod $methodReflection, string $methodWrapper = null): MethodReflection
{
$phpDocParameterTypes = [];
$phpDocReturnType = null;
$phpDocThrowType = null;
$phpDocIsDeprecated = false;
$phpDocIsInternal = false;
$phpDocIsFinal = false;
if ($methodReflection->getDocComment() !== false) {
$phpDocBlock = PhpDocBlock::resolvePhpDocBlockForMethod(
Broker::getInstance(),
$methodReflection->getDocComment(),
$methodReflection->getDeclaringClass()->getName(),
$methodReflection->getName(),
$methodReflection->getFileName()
);
$resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc(
$phpDocBlock->getFile(),
$phpDocBlock->getClass(),
null,
$phpDocBlock->getDocComment()
);
$phpDocParameterTypes = array_map(function (ParamTag $tag): Type {
return $tag->getType();
}, $resolvedPhpDoc->getParamTags());
$phpDocReturnType = $resolvedPhpDoc->getReturnTag() !== null ? $resolvedPhpDoc->getReturnTag()->getType() : null;
$phpDocThrowType = $resolvedPhpDoc->getThrowsTag() !== null ? $resolvedPhpDoc->getThrowsTag()->getType() : null;
$phpDocIsDeprecated = $resolvedPhpDoc->isDeprecated();
$phpDocIsInternal = $resolvedPhpDoc->isInternal();
$phpDocIsFinal = $resolvedPhpDoc->isFinal();
}
if ($methodWrapper) {
$methodReflection = new $methodWrapper($methodReflection);
}
return $this->methodReflectionFactory->create(
$classReflection,
null,
$methodReflection,
$phpDocParameterTypes,
$phpDocReturnType,
$phpDocThrowType,
$phpDocIsDeprecated,
$phpDocIsInternal,
$phpDocIsFinal
);
}
}