GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 72c85e...aa4912 )
by Hilari
02:23
created

CodeCoverageGenerator::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
3
use Behat\Behat\ApplicationFactory;
4
use PhpSpec\Console\Application;
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\ArgvInput;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\ConsoleOutput;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Class CodeCoverageGenerator
13
 */
14
class CodeCoverageGenerator extends Command
15
{
16
    /**
17
     * @var string
18
     */
19
    private $baseDir;
20
21
    /**
22
     * @var int
23
     */
24
    private $exitCode = 0;
25
26
    protected function configure()
27
    {
28
        $this->baseDir = realpath(__DIR__.'/..').'/';
29
30
        $this
31
            ->setName('code-coverage:generate')
32
            ->setDescription('Generates a code coverage report');
33
    }
34
35
    /**
36
     * Builds the code coverage clove report file
37
     *
38
     * @param InputInterface  $input
39
     * @param OutputInterface $output
40
     *
41
     * @return int|null|void
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $coverage = new PHP_CodeCoverage(null, $this->getFilter());
46
        $coverage->start('<tests>');
47
48
        $this->runPhpSpec();
49
        $this->runBehat();
50
51
        $coverage->stop();
52
        $this->writeReport($coverage);
53
54
        if ($this->exitCode !== 0) {
55
            exit($this->exitCode);
56
        }
57
    }
58
59
    /**
60
     * Writes the clover report
61
     * 
62
     * @param PHP_CodeCoverage $coverage
63
     */
64
    private function writeReport(PHP_CodeCoverage $coverage)
65
    {
66
        $writer = new PHP_CodeCoverage_Report_Clover;
67
        $writer->process($coverage, $this->getPath('clover.xml'));
68
    }
69
70
    /**
71
     * Runs php spec unit tests
72
     */
73
    private function runPhpSpec()
74
    {
75
        $input = new ArgvInput(['phpspec', 'run', '--format=pretty']);
76
        $app = new Application(null);
77
        $app->setAutoExit(false);
78
79
        $this->exitCode = $app->run($input, new ConsoleOutput());
80
    }
81
82
    /**
83
     * Runs php spec unit tests
84
     */
85
    private function runBehat()
86
    {
87
        define('BEHAT_BIN_PATH', realpath(__DIR__.'/../bin/behat'));
88
        $input = new ArgvInput(['behat']);
89
        $factory = new ApplicationFactory();
90
        $app = $factory->createApplication();
91
        $app->setAutoExit(false);
92
93
        $this->exitCode += $app->run($input, new ConsoleOutput());
94
    }
95
96
    /**
97
     * @return PHP_CodeCoverage_Filter
98
     */
99
    private function getFilter()
100
    {
101
        $filter = new PHP_CodeCoverage_Filter();
102
        $filter->addDirectoryToBlacklist($this->getPath('console'));
103
        $filter->addDirectoryToBlacklist($this->getPath('features'));
104
        $filter->addDirectoryToBlacklist($this->getPath('spec'));
105
        $filter->addDirectoryToBlacklist($this->getPath('vendor'));
106
107
        return $filter;
108
    }
109
110
    /**
111
     * @param string $path
112
     *
113
     * @return string
114
     */
115
    private function getPath($path)
116
    {
117
        return $this->baseDir.$path;
118
    }
119
}
120