|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of CaptainHook. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CaptainHook\App\Git\ChangedFiles\Detector; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\Console\IO; |
|
15
|
|
|
use CaptainHook\App\Git\ChangedFiles\Detecting; |
|
16
|
|
|
use CaptainHook\App\Hooks; |
|
17
|
|
|
use SebastianFeldmann\Git\Repository; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Factory class |
|
21
|
|
|
* |
|
22
|
|
|
* Responsible for finding the previous - current ranges in every scenario |
|
23
|
|
|
* |
|
24
|
|
|
* @package CaptainHook |
|
25
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
26
|
|
|
* @link https://github.com/captainhookphp/captainhook |
|
27
|
|
|
* @since Class available since Release 5.15.0 |
|
28
|
|
|
*/ |
|
29
|
|
|
class Factory |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* List of available range detectors |
|
33
|
|
|
* |
|
34
|
|
|
* @var array<string, string> |
|
35
|
|
|
*/ |
|
36
|
|
|
private static array $detectors = [ |
|
37
|
|
|
'hook:pre-push' => '\\CaptainHook\\App\\Git\\ChangedFiles\\Detector\\PrePush', |
|
38
|
|
|
'hook:post-rewrite' => '\\CaptainHook\\App\\Git\\ChangedFiles\\Detector\\PostRewrite', |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns a ChangedFiles Detector |
|
43
|
|
|
* |
|
44
|
|
|
* @param \CaptainHook\App\Console\IO $io |
|
45
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
|
46
|
|
|
* @return \CaptainHook\App\Git\ChangedFiles\Detecting |
|
47
|
|
|
*/ |
|
48
|
19 |
|
public function getDetector(IO $io, Repository $repository): Detecting |
|
49
|
|
|
{ |
|
50
|
19 |
|
$command = $io->getArgument(Hooks::ARG_COMMAND); |
|
51
|
|
|
|
|
52
|
|
|
/** @var \CaptainHook\App\Git\ChangedFiles\Detecting $class */ |
|
53
|
19 |
|
$class = self::$detectors[$command] ?? '\\CaptainHook\\App\\Git\\ChangedFiles\\Detector\\Fallback'; |
|
54
|
19 |
|
return new $class($io, $repository); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.