88use PhpParser \Node \Stmt \ClassMethod ;
99use PhpParser \Node \Stmt \Function_ ;
1010use PHPStan \Analyser \Scope ;
11- use PHPStan \BetterReflection \Reflection \Adapter \FakeReflectionAttribute ;
12- use PHPStan \BetterReflection \Reflection \Adapter \ReflectionAttribute ;
13- use PHPStan \BetterReflection \Reflection \ReflectionAttribute as BetterReflectionAttribute ;
14- use PHPStan \BetterReflection \Reflector \Reflector ;
11+ use PHPStan \Reflection \AttributeReflection ;
1512use PHPStan \Reflection \FunctionReflection ;
1613use PHPStan \Reflection \MethodReflection ;
14+ use PHPStan \Reflection \ReflectionProvider ;
1715use PHPStan \Type \Type ;
1816use PHPStan \Type \UnionType ;
1917use Spaze \PHPStan \Rules \Disallowed \Disallowed ;
@@ -28,7 +26,7 @@ class Allowed
2826
2927 private Formatter $ formatter ;
3028
31- private Reflector $ reflector ;
29+ private ReflectionProvider $ reflectionProvider ;
3230
3331 private Identifier $ identifier ;
3432
@@ -39,13 +37,13 @@ class Allowed
3937
4038 public function __construct (
4139 Formatter $ formatter ,
42- Reflector $ reflector ,
40+ ReflectionProvider $ reflectionProvider ,
4341 Identifier $ identifier ,
4442 GetAttributesWhenInSignature $ attributesWhenInSignature ,
4543 AllowedPath $ allowedPath
4644 ) {
4745 $ this ->formatter = $ formatter ;
48- $ this ->reflector = $ reflector ;
46+ $ this ->reflectionProvider = $ reflectionProvider ;
4947 $ this ->identifier = $ identifier ;
5048 $ this ->attributesWhenInSignature = $ attributesWhenInSignature ;
5149 $ this ->allowedPath = $ allowedPath ;
@@ -203,7 +201,7 @@ private function hasAllowedParamsInAllowed(Scope $scope, ?array $args, Disallowe
203201
204202
205203 /**
206- * @param list<FakeReflectionAttribute|ReflectionAttribute|BetterReflectionAttribute > $attributes
204+ * @param list<AttributeReflection > $attributes
207205 * @param list<string> $allowConfig
208206 * @return bool
209207 */
@@ -247,32 +245,29 @@ private function getArgType(array $args, Scope $scope, Param $param): ?Type
247245
248246 /**
249247 * @param Scope $scope
250- * @return list<FakeReflectionAttribute>|list<ReflectionAttribute >
248+ * @return list<AttributeReflection >
251249 */
252250 private function getAttributes (Scope $ scope ): array
253251 {
254- return $ scope ->isInClass () ? $ scope ->getClassReflection ()->getNativeReflection ()-> getAttributes () : [];
252+ return $ scope ->isInClass () ? $ scope ->getClassReflection ()->getAttributes () : [];
255253 }
256254
257255
258256 /**
259257 * @param Node|null $node
260258 * @param Scope $scope
261- * @return list<FakeReflectionAttribute|ReflectionAttribute|BetterReflectionAttribute >
259+ * @return list<AttributeReflection >
262260 */
263261 private function getCallAttributes (?Node $ node , Scope $ scope ): array
264262 {
265263 $ function = $ scope ->getFunction ();
266- if ($ function instanceof MethodReflection) {
267- return $ scope ->isInClass () ? $ scope ->getClassReflection ()->getNativeReflection ()->getMethod ($ function ->getName ())->getAttributes () : [];
268- } elseif ($ function instanceof FunctionReflection) {
269- return $ this ->reflector ->reflectFunction ($ function ->getName ())->getAttributes ();
270- } elseif ($ function === null ) {
271- if ($ node instanceof ClassMethod && $ scope ->isInClass ()) {
272- return $ scope ->getClassReflection ()->getNativeReflection ()->getMethod ($ node ->name ->name )->getAttributes ();
273- } elseif ($ node instanceof Function_) {
274- return $ this ->reflector ->reflectFunction ($ node ->name ->name )->getAttributes ();
275- }
264+ if ($ function !== null ) {
265+ return $ function ->getAttributes ();
266+ } elseif ($ node instanceof ClassMethod && $ scope ->isInClass ()) {
267+ return $ scope ->getClassReflection ()->getNativeMethod ($ node ->name ->name )->getAttributes ();
268+ } elseif ($ node instanceof Function_ && $ node ->namespacedName !== null ) {
269+ return $ this ->reflectionProvider ->getFunction ($ node ->namespacedName , $ scope )->getAttributes ();
270+ } else {
276271 $ attributes = $ this ->attributesWhenInSignature ->get ($ scope );
277272 if ($ attributes !== null ) {
278273 return $ attributes ;
@@ -284,16 +279,17 @@ private function getCallAttributes(?Node $node, Scope $scope): array
284279
285280 /**
286281 * @param Scope $scope
287- * @return list<FakeReflectionAttribute>|list<ReflectionAttribute >
282+ * @return list<AttributeReflection >
288283 */
289284 private function getAllMethodAttributes (Scope $ scope ): array
290285 {
291286 if (!$ scope ->isInClass ()) {
292287 return [];
293288 }
294289 $ attributes = [];
295- foreach ($ scope ->getClassReflection ()->getNativeReflection ()->getMethods () as $ method ) {
296- $ methodAttributes = $ method ->getAttributes ();
290+ $ classReflection = $ scope ->getClassReflection ();
291+ foreach ($ classReflection ->getNativeReflection ()->getMethods () as $ method ) {
292+ $ methodAttributes = $ classReflection ->getNativeMethod ($ method ->getName ())->getAttributes ();
297293 if ($ methodAttributes !== []) {
298294 $ attributes = array_merge ($ attributes , $ methodAttributes );
299295 }
0 commit comments