Completed
Push — master ( 5635b0...3b50b8 )
by Christian
02:38
created

ForbiddenFiles   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 47
ccs 12
cts 12
cp 1
rs 10
c 1
b 1
f 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 14 2
A getName() 0 4 1
A checkSupport() 0 4 1
1
<?php
2
3
namespace uuf6429\ElderBrother\Action;
4
5
use RuntimeException;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use uuf6429\ElderBrother\Change\FileList;
9
10
class ForbiddenFiles extends ActionAbstract
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 3
    public function __construct(FileList $files, $reason)
27
    {
28 3
        $this->files = $files;
29 3
        $this->reason = $reason;
30 3
    }
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 3
    public function execute(InputInterface $input, OutputInterface $output)
43
    {
44 3
        $files = $this->files->toArray();
45
46 3
        if (count($files)) {
47 2
            $bull = PHP_EOL . '- ';
48 2
            throw new RuntimeException(
49
                sprintf(
50 2
                    'The following files are not allowed:%s',
51 2
                    rtrim($bull . implode($bull, $files) . PHP_EOL . $this->reason)
52
                )
53
            );
54
        }
55 1
    }
56
}
57