Test Failed
Push — master ( f235c1...2c36df )
by Nuno
01:49
created

ModelScopeMethodExtension::hasMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
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\Database\Eloquent;
15
16
use Mockery;
17
use PHPStan\Reflection\ClassReflection;
18
use PHPStan\Reflection\MethodReflection;
19
20
final class ModelScopeMethodExtension extends ModelMethodExtension
21
{
22
    public function hasMethod(ClassReflection $classReflection, string $methodName): bool
23
    {
24
        $scopeMethodName = 'scope'.ucfirst($methodName);
25
26
        return parent::hasMethod($classReflection, $scopeMethodName);
27
    }
28
29
    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
30
    {
31
        $scopeMethodName = 'scope'.ucfirst($methodName);
32
33
        $methodReflection = parent::getMethod($classReflection, $scopeMethodName);
34
35
        /** @var \PHPStan\Reflection\FunctionVariantWithPhpDocs $variant */
36
        $variant = $methodReflection->getVariants()[0];
37
        $parameters = $variant->getParameters();
38
        unset($parameters[0]); // The query argument.
39
40
        $variant = Mockery::mock($variant);
41
        $variant->shouldReceive('getParameters')
42
            ->andReturn($parameters);
43
44
        $methodReflection->shouldReceive('getVariants')
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on PHPStan\Reflection\MethodReflection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        $methodReflection->/** @scrutinizer ignore-call */ 
45
                           shouldReceive('getVariants')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
            ->andReturn([$variant]);
46
47
        return $methodReflection;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    protected function searchIn(ClassReflection $classReflection): array
54
    {
55
        return [$classReflection->getName()];
56
    }
57
}
58