Passed
Push — master ( 89e590...da1197 )
by Nuno
02:23
created

FacadeMethodExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setBroker() 0 3 1
A getMethod() 0 7 1
A hasMethod() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Code Analyse.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace NunoMaduro\LaravelCodeAnalyse\Extensions;
15
16
use PHPStan\Broker\Broker;
17
use Illuminate\Support\Facades\Facade;
18
use PHPStan\Reflection\ClassReflection;
19
use PHPStan\Reflection\MethodReflection;
20
use PHPStan\Reflection\BrokerAwareExtension;
21
use PHPStan\Reflection\MethodsClassReflectionExtension;
22
use NunoMaduro\LaravelCodeAnalyse\FacadeConcreteClassResolver;
0 ignored issues
show
Bug introduced by
The type NunoMaduro\LaravelCodeAn...deConcreteClassResolver was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
24
final class FacadeMethodExtension implements MethodsClassReflectionExtension, BrokerAwareExtension
25
{
26
27
    /**
28
     * @var \PHPStan\Broker\Broker
29
     */
30
    private $broker;
31
32
    /**
33
     * @param \PHPStan\Broker\Broker $broker
34
     */
35
    public function setBroker(Broker $broker): void
36
    {
37
        $this->broker = $broker;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function hasMethod(ClassReflection $classReflection, string $methodName): bool
44
    {
45
        if ($classReflection->isSubclassOf(Facade::class)) {
46
            $facadeClass = $classReflection->getNativeReflection()
47
                ->getName();
48
49
            if ($concrete = $facadeClass::getFacadeRoot()) {
50
                return $this->broker->getClass($concrete)
51
                    ->hasNativeMethod($methodName);
52
            }
53
        }
54
55
        return false;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
62
    {
63
        $facadeClass = $classReflection->getNativeReflection()
64
            ->getName();
65
66
        return $this->broker->getClass($facadeClass::getFacadeRoot())
67
            ->getNativeMethod($methodName);
68
    }
69
}
70