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
@@ -37,12 +35,12 @@ class Allowed
3735
3836 public function __construct (
3937 Formatter $ formatter ,
40- Reflector $ reflector ,
38+ ReflectionProvider $ reflectionProvider ,
4139 Identifier $ identifier ,
4240 AllowedPath $ allowedPath
4341 ) {
4442 $ this ->formatter = $ formatter ;
45- $ this ->reflector = $ reflector ;
43+ $ this ->reflectionProvider = $ reflectionProvider ;
4644 $ this ->identifier = $ identifier ;
4745 $ this ->allowedPath = $ allowedPath ;
4846 }
@@ -199,7 +197,7 @@ private function hasAllowedParamsInAllowed(Scope $scope, ?array $args, Disallowe
199197
200198
201199 /**
202- * @param list<FakeReflectionAttribute|ReflectionAttribute|BetterReflectionAttribute > $attributes
200+ * @param list<AttributeReflection > $attributes
203201 * @param list<string> $allowConfig
204202 * @return bool
205203 */
@@ -243,49 +241,46 @@ private function getArgType(array $args, Scope $scope, Param $param): ?Type
243241
244242 /**
245243 * @param Scope $scope
246- * @return list<FakeReflectionAttribute>|list<ReflectionAttribute >
244+ * @return list<AttributeReflection >
247245 */
248246 private function getAttributes (Scope $ scope ): array
249247 {
250- return $ scope ->isInClass () ? $ scope ->getClassReflection ()->getNativeReflection ()-> getAttributes () : [];
248+ return $ scope ->isInClass () ? $ scope ->getClassReflection ()->getAttributes () : [];
251249 }
252250
253251
254252 /**
255253 * @param Node|null $node
256254 * @param Scope $scope
257- * @return list<FakeReflectionAttribute|ReflectionAttribute|BetterReflectionAttribute >
255+ * @return list<AttributeReflection >
258256 */
259257 private function getCallAttributes (?Node $ node , Scope $ scope ): array
260258 {
261259 $ function = $ scope ->getFunction ();
262- if ($ function instanceof MethodReflection) {
263- return $ scope ->isInClass () ? $ scope ->getClassReflection ()->getNativeReflection ()->getMethod ($ function ->getName ())->getAttributes () : [];
264- } elseif ($ function instanceof FunctionReflection) {
265- return $ this ->reflector ->reflectFunction ($ function ->getName ())->getAttributes ();
266- } elseif ($ function === null ) {
267- if ($ node instanceof ClassMethod && $ scope ->isInClass ()) {
268- return $ scope ->getClassReflection ()->getNativeReflection ()->getMethod ($ node ->name ->name )->getAttributes ();
269- } elseif ($ node instanceof Function_) {
270- return $ this ->reflector ->reflectFunction ($ node ->name ->name )->getAttributes ();
271- }
260+ if ($ function !== null ) {
261+ return $ function ->getAttributes ();
262+ } elseif ($ node instanceof ClassMethod && $ scope ->isInClass ()) {
263+ return $ scope ->getClassReflection ()->getNativeMethod ($ node ->name ->name )->getAttributes ();
264+ } elseif ($ node instanceof Function_ && $ node ->namespacedName !== null ) {
265+ return $ this ->reflectionProvider ->getFunction ($ node ->namespacedName , $ scope )->getAttributes ();
272266 }
273267 return [];
274268 }
275269
276270
277271 /**
278272 * @param Scope $scope
279- * @return list<FakeReflectionAttribute>|list<ReflectionAttribute >
273+ * @return list<AttributeReflection >
280274 */
281275 private function getAllMethodAttributes (Scope $ scope ): array
282276 {
283277 if (!$ scope ->isInClass ()) {
284278 return [];
285279 }
286280 $ attributes = [];
287- foreach ($ scope ->getClassReflection ()->getNativeReflection ()->getMethods () as $ method ) {
288- $ methodAttributes = $ method ->getAttributes ();
281+ $ classReflection = $ scope ->getClassReflection ();
282+ foreach ($ classReflection ->getNativeReflection ()->getMethods () as $ method ) {
283+ $ methodAttributes = $ classReflection ->getNativeMethod ($ method ->getName ())->getAttributes ();
289284 if ($ methodAttributes !== []) {
290285 $ attributes = array_merge ($ attributes , $ methodAttributes );
291286 }
0 commit comments