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\File\Action; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Config; |
15
|
|
|
use CaptainHook\App\Console\IO; |
16
|
|
|
use CaptainHook\App\Exception\ActionFailed; |
17
|
|
|
use CaptainHook\App\Hook\Action; |
18
|
|
|
use Exception; |
19
|
|
|
use SebastianFeldmann\Git\Repository; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class IsEmpty |
23
|
|
|
* |
24
|
|
|
* @package CaptainHook |
25
|
|
|
* @author Felix Edelmann <[email protected]> |
26
|
|
|
* @link https://github.com/captainhookphp/captainhook |
27
|
|
|
* @since Class available since Release 5.4.0 |
28
|
|
|
*/ |
29
|
|
|
class IsEmpty extends Check |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Actual action name for better error messages |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $actionName = 'IsEmpty'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Executes the action |
40
|
|
|
* |
41
|
|
|
* @param \CaptainHook\App\Config $config |
42
|
|
|
* @param \CaptainHook\App\Console\IO $io |
43
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
44
|
|
|
* @param \CaptainHook\App\Config\Action $action |
45
|
|
|
* @return void |
46
|
|
|
* @throws \Exception |
47
|
|
|
*/ |
48
|
|
|
public function execute(Config $config, IO $io, Repository $repository, Config\Action $action): void |
49
|
|
|
{ |
50
|
|
|
$failedFiles = 0; |
51
|
|
|
foreach ($this->getFiles($action->getOptions()) as $glob => $files) { |
52
|
|
|
if (!$this->areAllFilesEmpty($files)) { |
53
|
|
|
$io->write('- <error>FAIL</error> ' . $glob, true); |
54
|
|
|
$failedFiles++; |
55
|
|
|
} else { |
56
|
|
|
$io->write('- <info>OK</info> ' . $glob, true, IO::VERBOSE); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ($failedFiles > 0) { |
61
|
|
|
throw new ActionFailed('<error>Error: ' . $failedFiles . ' non-empty file(s)</error>'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$io->write('<info>All files are empty or don\'t exist</info>'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|