|
14 | 14 | use ShipMonk\PHPStan\DeadCode\Graph\ClassMethodRef; |
15 | 15 | use ShipMonk\PHPStan\DeadCode\Graph\ClassMethodUsage; |
16 | 16 | use ShipMonk\PHPStan\DeadCode\Graph\UsageOrigin; |
17 | | -use function array_merge; |
| 17 | +use function count; |
| 18 | +use function explode; |
18 | 19 | use function is_string; |
| 20 | +use function ltrim; |
19 | 21 | use function str_contains; |
20 | 22 | use function str_starts_with; |
21 | 23 |
|
@@ -61,15 +63,24 @@ public function getUsages( |
61 | 63 | $methodName = $method->getName(); |
62 | 64 |
|
63 | 65 | $externalDataProviderMethods = $this->getExternalDataProvidersFromAttributes($method); |
64 | | - $localDataProviderMethods = array_merge( |
65 | | - $this->getDataProvidersFromAnnotations($method->getDocComment()), |
66 | | - $this->getDataProvidersFromAttributes($method), |
67 | | - ); |
| 66 | + $annotationDataProviders = $this->getDataProvidersFromAnnotations($method->getDocComment()); |
| 67 | + $localDataProviderMethods = $this->getDataProvidersFromAttributes($method); |
68 | 68 |
|
69 | 69 | foreach ($externalDataProviderMethods as [$externalClassName, $externalMethodName]) { |
70 | 70 | $usages[] = $this->createUsage($externalClassName, $externalMethodName, "External data provider method, used by $className::$methodName"); |
71 | 71 | } |
72 | 72 |
|
| 73 | + foreach ($annotationDataProviders as $dataProvider) { |
| 74 | + $parts = explode('::', $dataProvider, 2); |
| 75 | + |
| 76 | + if (count($parts) === 2) { |
| 77 | + $providerClassName = ltrim($parts[0], '\\'); |
| 78 | + $usages[] = $this->createUsage($providerClassName, $parts[1], "External data provider method (annotation), used by $className::$methodName"); |
| 79 | + } else { |
| 80 | + $usages[] = $this->createUsage($className, $dataProvider, "Data provider method, used by $methodName"); |
| 81 | + } |
| 82 | + } |
| 83 | + |
73 | 84 | foreach ($localDataProviderMethods as $dataProvider) { |
74 | 85 | $usages[] = $this->createUsage($className, $dataProvider, "Data provider method, used by $methodName"); |
75 | 86 | } |
|
0 commit comments