Passed
Push — master ( af7a0d...c293f7 )
by Julien
01:06 queued 11s
created

RepositoryMagicFindExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasMethod() 0 15 5
A setBroker() 0 3 1
A getMethod() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mapado\RestClientSdk\PHPStan\Reflection;
6
7
use PHPStan\Broker\Broker;
8
use PHPStan\Reflection\BrokerAwareExtension;
9
use PHPStan\Reflection\ClassReflection;
10
use PHPStan\Reflection\Dummy\DummyMethodReflection;
11
use PHPStan\Reflection\MethodReflection;
12
use PHPStan\Reflection\MethodsClassReflectionExtension;
13
14
class RepositoryMagicFindExtension implements MethodsClassReflectionExtension, BrokerAwareExtension
15
{
16
    /** @var Broker */
17
    private $broker;
18
19
    public function setBroker(Broker $broker): void
20
    {
21
        $this->broker = $broker;
22
    }
23
24
    public function hasMethod(ClassReflection $classReflection, string $methodName): bool
25
    {
26
        if (0 !== mb_strpos($methodName, 'findBy')
27
            && 0 !== mb_strpos($methodName, 'findOneBy')
28
        ) {
29
            return false;
30
        }
31
        if ('Mapado\RestClientSdk\EntityRepository' === $classReflection->getName()) {
32
            return true;
33
        }
34
        if (!$this->broker->hasClass('Mapado\RestClientSdk\EntityRepository')) {
35
            return false;
36
        }
37
38
        return $classReflection->isSubclassOf('Mapado\RestClientSdk\EntityRepository');
39
    }
40
41
    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
42
    {
43
        return new DummyMethodReflection($methodName);
44
    }
45
}
46