Passed
Push — master ( 93e91b...83695f )
by Fabien
02:05
created

ProgressBarSubscriber::onAfterAnalysis()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\Command\Helper;
6
7
use Churn\Event\Event\AfterAnalysisEvent;
8
use Churn\Event\Event\AfterFileAnalysisEvent;
9
use Churn\Event\Event\BeforeAnalysisEvent;
10
use Churn\Event\Subscriber\AfterAnalysis;
11
use Churn\Event\Subscriber\AfterFileAnalysis;
12
use Churn\Event\Subscriber\BeforeAnalysis;
13
use Symfony\Component\Console\Helper\ProgressBar;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * @internal
18
 */
19
class ProgressBarSubscriber implements AfterAnalysis, AfterFileAnalysis, BeforeAnalysis
20
{
21
22
    /**
23
     * @var ProgressBar
24
     */
25
    private $progressBar;
26
27
    /**
28
     * @param OutputInterface $output The console output.
29
     */
30
    public function __construct(OutputInterface $output)
31
    {
32
        $this->progressBar = new ProgressBar($output);
33
    }
34
35
    /**
36
     * @param AfterAnalysisEvent $event The event triggered when the analysis is done.
37
     */
38
    public function onAfterAnalysis(AfterAnalysisEvent $event): void
39
    {
40
        $this->progressBar->finish();
41
    }
42
43
    /**
44
     * @param BeforeAnalysisEvent $event The event triggered when the analysis starts.
45
     */
46
    public function onBeforeAnalysis(BeforeAnalysisEvent $event): void
47
    {
48
        $this->progressBar->start();
49
    }
50
51
    /**
52
     * @param AfterFileAnalysisEvent $event The event triggered when the analysis of a file is done.
53
     */
54
    public function onAfterFileAnalysis(AfterFileAnalysisEvent $event): void
55
    {
56
        $this->progressBar->advance();
57
    }
58
}
59