AbstractBuilderMethodExtension::hasMethod()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Phpstan Laravel.
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\PhpstanLaravel;
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) && $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);
63
        $mock->shouldReceive('isStatic')
64
            ->andReturn(true);
65
66
        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...
67
    }
68
}
69