|
9 | 9 | use function array_slice;
|
10 | 10 | use function explode;
|
11 | 11 | use function sprintf;
|
12 |
| -use function str_starts_with; |
13 | 12 | use function strtolower;
|
14 | 13 |
|
15 | 14 | final class RestrictedInternalMethodUsageExtension implements RestrictedMethodUsageExtension
|
16 | 15 | {
|
17 | 16 |
|
| 17 | + public function __construct(private RestrictedInternalUsageHelper $helper) |
| 18 | + { |
| 19 | + } |
| 20 | + |
18 | 21 | public function isRestrictedMethodUsage(
|
19 | 22 | ExtendedMethodReflection $methodReflection,
|
20 | 23 | Scope $scope,
|
21 | 24 | ): ?RestrictedUsage
|
22 | 25 | {
|
23 | 26 | $isMethodInternal = $methodReflection->isInternal()->yes();
|
24 |
| - $isDeclaringClassInternal = $methodReflection->getDeclaringClass()->isInternal(); |
| 27 | + $declaringClass = $methodReflection->getDeclaringClass(); |
| 28 | + $isDeclaringClassInternal = $declaringClass->isInternal(); |
25 | 29 | if (!$isMethodInternal && !$isDeclaringClassInternal) {
|
26 | 30 | return null;
|
27 | 31 | }
|
28 | 32 |
|
29 |
| - $currentNamespace = $scope->getNamespace(); |
30 |
| - $declaringClassName = $methodReflection->getDeclaringClass()->getName(); |
31 |
| - $namespace = array_slice(explode('\\', $declaringClassName), 0, -1)[0] ?? null; |
32 |
| - if ($currentNamespace === null) { |
33 |
| - return $this->buildRestrictedUsage($methodReflection, $namespace, $isMethodInternal); |
34 |
| - } |
35 |
| - |
36 |
| - $currentNamespace = explode('\\', $currentNamespace)[0]; |
37 |
| - if (str_starts_with($namespace . '\\', $currentNamespace . '\\')) { |
| 33 | + $declaringClassName = $declaringClass->getName(); |
| 34 | + if (!$this->helper->shouldBeReported($scope, $declaringClassName)) { |
38 | 35 | return null;
|
39 | 36 | }
|
40 | 37 |
|
41 |
| - return $this->buildRestrictedUsage($methodReflection, $namespace, $isMethodInternal); |
42 |
| - } |
43 |
| - |
44 |
| - private function buildRestrictedUsage(ExtendedMethodReflection $methodReflection, ?string $namespace, bool $isMethodInternal): RestrictedUsage |
45 |
| - { |
| 38 | + $namespace = array_slice(explode('\\', $declaringClassName), 0, -1)[0] ?? null; |
46 | 39 | if ($namespace === null) {
|
47 | 40 | if (!$isMethodInternal) {
|
48 | 41 | return RestrictedUsage::create(
|
|
0 commit comments