Completed
Push — master ( 89afb5...b5231e )
by Christian
02:57
created

ForbiddenFiles::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
namespace uuf6429\ElderBrother\Action;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use uuf6429\ElderBrother\Change\FileList;
8
use RuntimeException;
9
10
class ForbiddenFiles implements ActionInterface
11
{
12
    /**
13
     * @var FileList
14
     */
15
    protected $files;
16
17
    /** @var string */
18
    protected $reason;
19
20
    /**
21
     * Will stop process if $files is not empty, for the reason specified in $reason.
22
     *
23
     * @param FileList $files
24
     * @param string   $reason
25
     */
26
    public function __construct(FileList $files, $reason)
27
    {
28
        $this->files = $files;
29
        $this->reason = $reason;
30
    }
31
32
    public function getName()
33
    {
34
        return 'Disallow files (ForbiddenFiles)';
35
    }
36
37
    public function checkSupport()
38
    {
39
        // no special dependencies
40
    }
41
42
    public function execute(InputInterface $input, OutputInterface $output)
43
    {
44
        $files = $this->files->toArray();
45
46
        if (count($files)) {
47
            $bull = PHP_EOL . '- ';
48
            throw new RuntimeException(
49
                sprintf(
50
                    'The following files are not allowed:%s',
51
                    rtrim($bull . implode($bull, $files) . PHP_EOL . $this->reason)
52
                )
53
            );
54
        }
55
    }
56
}
57