ProgressBarSubscriber::onAfterAnalysis()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\Command\Helper;
6
7
use Churn\Event\Event\AfterAnalysis as AfterAnalysisEvent;
8
use Churn\Event\Event\AfterFileAnalysis as AfterFileAnalysisEvent;
9
use Churn\Event\Event\BeforeAnalysis as 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
final class ProgressBarSubscriber implements AfterAnalysis, AfterFileAnalysis, BeforeAnalysis
20
{
21
    /**
22
     * @var ProgressBar
23
     */
24
    private $progressBar;
25
26
    /**
27
     * @param OutputInterface $output The console output.
28
     */
29
    public function __construct(OutputInterface $output)
30
    {
31
        $this->progressBar = new ProgressBar($output);
32
    }
33
34
    /**
35
     * @param AfterAnalysisEvent $event The event triggered when the analysis is done.
36
     */
37
    #[\Override]
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
    #[\Override]
47
    public function onBeforeAnalysis(BeforeAnalysisEvent $event): void
48
    {
49
        $this->progressBar->start();
50
    }
51
52
    /**
53
     * @param AfterFileAnalysisEvent $event The event triggered when the analysis of a file is done.
54
     */
55
    #[\Override]
56
    public function onAfterFileAnalysis(AfterFileAnalysisEvent $event): void
57
    {
58
        $this->progressBar->advance();
59
    }
60
}
61