Passed
Push — rm-test ( e2c1fb )
by Sebastian
03:48
created

Fallback::getChangedFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
ccs 7
cts 8
cp 0.875
crap 2.0078
rs 10
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\Git\ChangedFiles\Detector;
15
use CaptainHook\App\Git\Rev\Util;
16
use CaptainHook\App\Hooks;
17
18
/**
19
 * Class Fallback
20
 *
21
 * This class should not be used it is just a fallback if the `pre-push` or `post-rewrite`
22
 * variants are somehow not applicable.
23
 *
24
 * @package CaptainHook
25
 * @author  Sebastian Feldmann <[email protected]>
26
 * @link    https://github.com/captainhook-git/captainhook
27
 * @since   Class available since Release 5.20.0
28
 */
29
class Fallback extends Detector
30
{
31
    /**
32
     * Returns the list of changed files in a best-guess kind of way
33
     *
34
     * @param  array<string> $filter
35
     * @return array<string>
36
     */
37 26
    public function getChangedFiles(array $filter = []): array
38
    {
39 26
        $previousHead = $this->io->getArgument(Hooks::ARG_PREVIOUS_HEAD, 'HEAD@{1}');
40 26
        if (Util::isZeroHash($previousHead)) {
41
            return [];
42
        }
43
44 26
        return $this->repository->getDiffOperator()->getChangedFiles(
45 26
            $previousHead,
46 26
            'HEAD',
47 26
            $filter
48 26
        );
49
    }
50
}
51