Completed
Push — master ( 6d9bc6...2c6699 )
by Christian
02:48
created

ActionAbstract   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 59
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
getName() 0 1 ?
isSupported() 0 1 ?
execute() 0 1 ?
A setConfig() 0 4 1
A createProgressBar() 0 13 2
1
<?php
2
3
namespace uuf6429\ElderBrother\Action;
4
5
use Psr\Log;
6
use Symfony\Component\Console\Helper\ProgressBar;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\NullOutput;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use uuf6429\ElderBrother\Config;
11
12
abstract class ActionAbstract implements Config\ConfigAwareInterface, Log\LoggerAwareInterface
13
{
14
    use Log\LoggerAwareTrait;
15
16
    /**
17
     * @var Config\ConfigInterface
18
     */
19
    protected $config;
20
21
    /**
22
     * Returns name of this action (possibly with some extra info).
23
     *
24
     * @return string
25
     */
26
    abstract public function getName();
27
28
    /**
29
     * Returns false when action is not supported (eg: missing lib etc).
30
     *
31
     * @return bool
32
     */
33
    abstract public function isSupported();
34
35
    /**
36
     * Execute action for the given parameters.
37
     *
38
     * @param InputInterface  $input
39
     * @param OutputInterface $output
40
     */
41
    abstract public function execute(InputInterface $input, OutputInterface $output);
42
43
    /**
44
     * @param InputInterface  $input
45
     * @param OutputInterface $output
46
     *
47
     * @return ProgressBar
48
     */
49 7
    protected function createProgressBar(InputInterface $input, OutputInterface $output)
50
    {
51 7
        if ($input->hasParameterOption('no-progress')) {
52
            $output = new NullOutput();
53
        }
54
55 7
        $progress = new ProgressBar($output);
56 7
        $progress->setMessage('');
57 7
        $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message%');
58 7
        $progress->setRedrawFrequency(1);
59
60 7
        return $progress;
61
    }
62
63
    /**
64
     * @param Config\ConfigInterface $config
65
     */
66 1
    public function setConfig(Config\ConfigInterface $config)
67
    {
68 1
        $this->config = $config;
69 1
    }
70
}
71