Completed
Push — master ( d372d6...3eec25 )
by Christian
02:37
created

RiskyFiles::isSupported()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 uuf6429\ElderBrother\Exception\RecoverableException;
9
10
class RiskyFiles extends ActionAbstract
11
{
12
    /**
13
     * @var FileList
14
     */
15
    protected $files;
16
17
    /** @var string */
18
    protected $reason;
19
20
    /**
21
     * Will show a warning if `$files` is not empty, for the reason specified in `$reason`.
22
     *
23
     * @param FileList $files
24
     * @param string   $reason
25
     */
26 4
    public function __construct(FileList $files, $reason)
27
    {
28 4
        $this->files = $files;
29 4
        $this->reason = $reason;
30 4
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getName()
36
    {
37
        return 'Show warning for files (RiskyFiles)';
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public function isSupported()
44
    {
45 1
        return true; // no special dependencies
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 3
    public function execute(InputInterface $input, OutputInterface $output)
52
    {
53 3
        $files = $this->files->toArray();
54
55 3
        if (count($files)) {
56 2
            $bull = PHP_EOL . '- ';
57 2
            throw new RecoverableException(
58
                sprintf(
59 2
                    'The following files are a potential risk:%s',
60 2
                    rtrim($bull . implode($bull, $files) . PHP_EOL . $this->reason)
61
                )
62
            );
63
        }
64 1
    }
65
}
66