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

ActionAbstract   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 57
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

5 Methods

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