Completed
Push — develop ( 2faf16...be2583 )
by ANTHONIUS
15s queued 11s
created

CoverageController::afterReportProcess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/behat-coverage-extension project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\Behat\Coverage\Controller\Cli;
15
16
use Behat\Testwork\Cli\Controller;
17
use Doyo\Behat\Coverage\Bridge\Symfony\Event;
18
use Doyo\Behat\Coverage\Event\CoverageEvent;
19
use Doyo\Behat\Coverage\Event\ReportEvent;
20
use Symfony\Component\Console\Command\Command;
21
use Symfony\Component\Console\Input\InputInterface;
22
use Symfony\Component\Console\Input\InputOption;
23
use Symfony\Component\Console\Output\OutputInterface;
24
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
25
26
/**
27
 * Code Coverage Cli Controller.
28
 *
29
 * @author Anthonius Munthi <[email protected]>
30
 */
31
class CoverageController implements Controller, EventSubscriberInterface
32
{
33
    /**
34
     * @var bool
35
     */
36
    private $coverageEnabled = false;
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 4
    public function configure(Command $command)
42
    {
43 4
        $command->addOption('coverage', null, InputOption::VALUE_NONE, 'Collecting code coverage');
44
    }
45
46 6
    public static function getSubscribedEvents()
47
    {
48
        return [
49 3
            ReportEvent::BEFORE_PROCESS => [
50 6
                ['validateEvent', 1000],
51
                ['beforeReportProcess']
52
            ],
53 3
            ReportEvent::AFTER_PROCESS    => ['afterReportProcess', 10000],
54 6
            CoverageEvent::COMPLETED => ['validateEvent', 10000],
55 6
            CoverageEvent::BEFORE_REFRESH => ['validateEvent', 10000],
56 6
            CoverageEvent::BEFORE_START   => ['validateEvent', 10000],
57 6
            CoverageEvent::BEFORE_STOP    => ['validateEvent', 10000],
58
        ];
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 4
    public function execute(InputInterface $input, OutputInterface $output)
65
    {
66 4
        if ($input->hasParameterOption(['--coverage'])) {
67 4
            $this->coverageEnabled = true;
68
        }
69
    }
70
71 8
    public function validateEvent(Event $event)
72
    {
73 8
        if (!$this->coverageEnabled) {
74 1
            $event->stopPropagation();
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\EventD...vent::stopPropagation() has been deprecated: since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

74
            /** @scrutinizer ignore-deprecated */ $event->stopPropagation();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
75
        }
76
    }
77
78 4
    public function beforeReportProcess(ReportEvent $event)
79
    {
80 4
        $event->getConsoleIO()->section('generating code coverage report');
81
    }
82
83 4
    public function afterReportProcess(ReportEvent $event)
84
    {
85 4
        $io = $event->getConsoleIO();
86
87 4
        if(!$io->hasError()){
88 4
            $io->success('behat code coverage generated');
89
        }else{
90 1
            $io->error('behat generate code coverage error');
91
        }
92
    }
93
}
94