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

ActionAbstract::createProgressBar()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 0
b 0
f 0
nc 2
cc 2
eloc 7
nop 3
crap 2.0116
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