1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of CaptainHook. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace CaptainHook\App\Hook\Condition\FileChanged; |
11
|
|
|
|
12
|
|
|
use CaptainHook\App\Console\IO; |
13
|
|
|
use CaptainHook\App\Hook\Condition\FileChanged; |
14
|
|
|
use SebastianFeldmann\Git\Repository; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class All |
18
|
|
|
* |
19
|
|
|
* The FileChange condition is applicable for `post-merge` and `post-checkout` hooks. |
20
|
|
|
* It checks if all configured files are updated within the last change set. |
21
|
|
|
* |
22
|
|
|
* @package CaptainHook |
23
|
|
|
* @author Sebastian Feldmann <[email protected]> |
24
|
|
|
* @link https://github.com/captainhookphp/captainhook |
25
|
|
|
* @since Class available since Release 4.2.0 |
26
|
|
|
*/ |
27
|
|
|
class All extends FileChanged |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Evaluates the condition |
31
|
|
|
* |
32
|
|
|
* @param \CaptainHook\App\Console\IO $io |
33
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
34
|
|
|
* @return bool |
35
|
|
|
*/ |
36
|
2 |
|
public function isTrue(IO $io, Repository $repository) : bool |
37
|
|
|
{ |
38
|
2 |
|
return $this->didAllFilesChange($this->getChangedFiles($io, $repository)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Check if all of the configured files where changed within the applied change set |
43
|
|
|
* |
44
|
|
|
* Important: If no files are configured this condition is always true. |
45
|
|
|
* |
46
|
|
|
* @param array $changedFiles |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
2 |
|
private function didAllFilesChange(array $changedFiles) : bool |
50
|
|
|
{ |
51
|
2 |
|
foreach ($this->filesToWatch as $file) { |
52
|
2 |
|
if (!in_array($file, $changedFiles)) { |
53
|
1 |
|
return false; |
54
|
|
|
} |
55
|
|
|
} |
56
|
1 |
|
return true; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|