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') |
|
|
|
|
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
|
|
|
|
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.