Passed
Push — master ( e83f83...b17f39 )
by Sebastian
02:59
created

Any::didAnyFileChange()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
cc 3
nc 3
nop 1
crap 3
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\Hook\Condition\FileChanged;
13
14
use CaptainHook\App\Console\IO;
15
use CaptainHook\App\Hook\Condition\FileChanged;
16
use SebastianFeldmann\Git\Repository;
17
18
/**
19
 * Class Any
20
 *
21
 * The FileChange condition is applicable for `post-merge` and `post-checkout` hooks.
22
 * For example it can be used to trigger an automatic composer install if the composer.json
23
 * or composer.lock file is changed during a checkout or merge.
24
 *
25
 * Example configuration:
26
 *
27
 * "action": "composer install"
28
 * "conditions": [
29
 *   {"exec": "\\CaptainHook\\App\\Hook\\Condition\\FileChange\\Any",
30
 *    "args": [
31
 *      [
32
 *        "composer.json",
33
 *        "composer.lock"
34
 *      ]
35
 *    ]}
36
 * ]
37
 *
38
 * @package CaptainHook
39
 * @author  Sebastian Feldmann <[email protected]>
40
 * @link    https://github.com/captainhookphp/captainhook
41
 * @since   Class available since Release 4.2.0
42
 */
43
class Any extends FileChanged
44
{
45
    /**
46
     * Check if any of the configured files was changed within the applied change set
47
     *
48
     * IMPORTANT: If no files are configured this condition is always false.
49
     *
50 3
     * @param  \CaptainHook\App\Console\IO       $io
51
     * @param  \SebastianFeldmann\Git\Repository $repository
52 3
     * @return bool
53
     */
54
    public function isTrue(IO $io, Repository $repository): bool
55
    {
56
        return $this->anyFileInHaystack($this->filesToWatch, $this->getChangedFiles($io, $repository));
57
    }
58
}
59