Completed
Push — master ( db7a5d...89e590 )
by Nuno
04:03
created

AbstractBuilderMethodExtension::getMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 2
rs 9.9332
c 0
b 0
f 0
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 Mockery;
17
use PHPStan\Broker\Broker;
18
use Illuminate\Database\Eloquent\Model;
19
use PHPStan\Reflection\ClassReflection;
20
use PHPStan\Reflection\MethodReflection;
21
use PHPStan\Reflection\BrokerAwareExtension;
22
use PHPStan\Reflection\MethodsClassReflectionExtension;
23
24
abstract class AbstractBuilderMethodExtension implements MethodsClassReflectionExtension, BrokerAwareExtension
25
{
26
    /**
27
     * @var \PHPStan\Broker\Broker
28
     */
29
    private $broker;
30
31
    /**
32
     * @param \PHPStan\Broker\Broker $broker
33
     */
34
    public function setBroker(Broker $broker): void
35
    {
36
        $this->broker = $broker;
37
    }
38
39
    /**
40
     * Returns the builder class.
41
     *
42
     * @return string
43
     */
44
    abstract public function getBuilderClass(): string;
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function hasMethod(ClassReflection $classReflection, string $methodName): bool
50
    {
51
        return $classReflection->isSubclassOf(Model::class) && $this->broker->getClass($this->getBuilderClass())
52
                ->hasNativeMethod($methodName);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
59
    {
60
        $methodReflection = $this->broker->getClass($this->getBuilderClass())
61
            ->getNativeMethod($methodName);
62
63
        $mock = Mockery::mock($methodReflection);
64
        $mock->shouldReceive('isStatic')
65
            ->andReturn(true);
66
67
        return $mock;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $mock returns the type Mockery\MockInterface which is incompatible with the type-hinted return PHPStan\Reflection\MethodReflection.
Loading history...
68
    }
69
}
70