Completed
Pull Request — master (#294)
by
unknown
03:26
created

ConsoleProgressWriter::getRedrawFrequency()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
rs 10
ccs 0
cts 2
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Ddeboer\DataImport\Writer;
4
5
use Ddeboer\DataImport\Reader\CountableReader;
6
use Ddeboer\DataImport\Writer;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Helper\ProgressBar;
9
10
/**
11
 * Writes output to the Symfony2 console
12
 *
13
 * @author David de Boer <[email protected]>
14
 */
15
class ConsoleProgressWriter implements Writer
16
{
17
    /**
18
     * @var OutputInterface
19
     */
20
    protected $output;
21
22
    /**
23
     * @var ProgressBar
24
     */
25
    protected $progress;
26
27
    /**
28
     * @var string
29
     */
30
    protected $verbosity;
31
32
    /**
33
     * @var CountableReader
34
     */
35
    protected $reader;
36
37
    /**
38
     * @var integer
39
     */
40
    protected $redrawFrequency;
41
42
    /**
43
     * @param OutputInterface $output
44
     * @param CountableReader $reader
45
     * @param string          $verbosity
46
     * @param integer         $redrawFrequency
47
     */
48 1
    public function __construct(
49
        OutputInterface $output,
50
        CountableReader $reader,
51
        $verbosity = 'debug',
52
        $redrawFrequency = 1
53
    ) {
54 1
        $this->output           = $output;
55 1
        $this->reader           = $reader;
56 1
        $this->verbosity        = $verbosity;
57 1
        $this->redrawFrequency  = $redrawFrequency;
58 1
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1
    public function prepare()
64
    {
65 1
        $this->progress = new ProgressBar($this->output, $this->reader->count());
66 1
        $this->progress->setFormat($this->verbosity);
67 1
        $this->progress->setRedrawFrequency($this->redrawFrequency);
68 1
        $this->progress->start();
69 1
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 1
    public function writeItem(array $item)
75
    {
76 1
        $this->progress->advance();
77 1
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 1
    public function finish()
83
    {
84 1
        $this->progress->finish();
85 1
    }
86
87
    /**
88
     * @return string
89
     */
90 1
    public function getVerbosity()
91
    {
92 1
        return $this->verbosity;
93
    }
94
95
    /**
96
     * @return integer
97
     */
98
    public function getRedrawFrequency()
99
    {
100
        return $this->redrawFrequency;
101
    }
102
}
103