Passed
Push — master ( 6369ea...229663 )
by Nuno
02:23
created

AbstractBuilderMethodExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setBroker() 0 3 1
A hasMethod() 0 4 3
A getMethod() 0 10 1
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;
15
16
use PHPStan\Broker\Broker;
17
use Illuminate\Database\Eloquent\Model;
18
use PHPStan\Reflection\ClassReflection;
19
use PHPStan\Reflection\MethodReflection;
20
use PHPStan\Reflection\BrokerAwareExtension;
21
use PHPStan\Reflection\MethodsClassReflectionExtension;
22
23
abstract class AbstractBuilderMethodExtension implements MethodsClassReflectionExtension, BrokerAwareExtension
24
{
25
    /**
26
     * @var \PHPStan\Broker\Broker
27
     */
28
    private $broker;
29
30
    /**
31
     * Returns the builder class.
32
     *
33
     * @return string
34
     */
35
    abstract public function getBuilderClass(): string;
36
37
    /**
38
     * @param \PHPStan\Broker\Broker $broker
39
     */
40
    public function setBroker(Broker $broker): void
41
    {
42
        $this->broker = $broker;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function hasMethod(ClassReflection $classReflection, string $methodName): bool
49
    {
50
        return ($classReflection->isSubclassOf(Model::class) || $classReflection->getName() === Model::class) && $this->broker->getClass($this->getBuilderClass())
51
                ->hasNativeMethod($methodName);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
58
    {
59
        $methodReflection = $this->broker->getClass($this->getBuilderClass())
60
            ->getNativeMethod($methodName);
61
62
        $mock = \Mockery::mock($methodReflection);
0 ignored issues
show
Bug introduced by
The type Mockery 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...
63
        $mock->shouldReceive('isStatic')
64
            ->andReturn(true);
65
66
        return $mock;
67
    }
68
}
69