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

BelongsToManyMethodExtension::setBroker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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 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
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
23
24
final class BelongsToManyMethodExtension 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
     * {@inheritdoc}
41
     */
42
    public function hasMethod(ClassReflection $classReflection, string $methodName): bool
43
    {
44
        return $classReflection->isSubclassOf(BelongsToMany::class) && $this->broker->getClass(BelongsToMany::class)
45
                ->hasNativeMethod($methodName);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
52
    {
53
        return $this->broker->getClass(BelongsToMany::class)
54
            ->getNativeMethod($methodName);
55
    }
56
}
57