Passed
Push — main ( 604bfc...f70419 )
by Sebastian
04:51
created

Factory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 26
rs 10
ccs 4
cts 4
cp 1
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDetector() 0 7 1
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);
0 ignored issues
show
Unused Code introduced by
The call to CaptainHook\App\Git\Chan...etecting::__construct() has too many arguments starting with $io. ( Ignorable by Annotation )

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

54
        return /** @scrutinizer ignore-call */ new $class($io, $repository);

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.

Loading history...
55
    }
56
}
57