Passed
Push — master ( 43b28b...a6262a )
by ANTHONIUS
03:49
created

RoboFile::watch()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 18
nc 1
nop 1
dl 0
loc 27
rs 9.6666
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/behat-code-coverage 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
use Lurker\Event\FilesystemEvent;
0 ignored issues
show
Bug introduced by
The type Lurker\Event\FilesystemEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Robo\Tasks;
0 ignored issues
show
Bug introduced by
The type Robo\Tasks was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
/**
18
 * This is project's console commands configuration for Robo task runner.
19
 *
20
 * @see http://robo.li/
21
 */
22
class RoboFile extends Tasks
23
{
24
    private $coverage = false;
25
26
    private $watch = false;
27
28
    /**
29
     * @param array $options
30
     */
31
    public function watch($options = ['coverage' => false])
32
    {
33
        $this->watch = true;
34
35
        $paths = [
36
            'src',
37
            'tests',
38
            'spec',
39
            'features',
40
        ];
41
42
        $this->taskWatch()
43
            ->monitor(
44
                $paths,
45
                function (FilesystemEvent $event) use ($options) {
46
                    $resource = (string) $event->getResource();
47
                    if (
48
                        false !== strpos($resource, 'build')
49
                        || false !== strpos($resource, 'var')
50
                    ) {
51
                        return;
52
                    }
53
                    $this->test($options);
0 ignored issues
show
Unused Code introduced by
The call to RoboFile::test() has too many arguments starting with $options. ( Ignorable by Annotation )

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

53
                    $this->/** @scrutinizer ignore-call */ 
54
                           test($options);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
54
                },
55
                FilesystemEvent::ALL
56
            )
57
            ->run();
58
    }
59
60
    public function test()
61
    {
62
        $this->taskExec('clear')->run();
63
64
        /** @var \Robo\Result[] $results */
65
        $results   = [];
66
        $results[] = $this->configurePhpSpec()->run();
67
        //$results[] = $this->configurePhpUnit()->run();
68
69
        if (!$this->watch) {
70
            $results[] = $this->configureBehat()->run();
71
        }
72
73
        $hasError = false;
74
        foreach ($results as $result) {
75
            if (0 !== $result->getExitCode()) {
76
                $hasError = true;
77
            }
78
        }
79
80
        if ($this->coverage) {
81
            $this->mergeCoverage();
82
        }
83
84
        if (!$this->watch) {
85
            if ($hasError) {
86
                throw new \Robo\Exception\TaskException($this, 'Tests failed');
0 ignored issues
show
Bug introduced by
The type Robo\Exception\TaskException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
87
            }
88
        }
89
    }
90
91
    public function coverage()
92
    {
93
        $this->coverage = true;
94
        $this->test();
95
    }
96
97
    public function mergeCoverage()
98
    {
99
        $this
100
            ->taskExec('phpdbg -qrr ./vendor/bin/phpcov')
101
            ->arg('merge')
102
            ->option('clover', 'build/logs/clover.xml')
103
            ->option('html', 'build/html')
104
            ->option('text')
105
            ->option('ansi')
106
            ->arg('build/cov')
107
            ->run();
108
    }
109
110
    /**
111
     * @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Behat
0 ignored issues
show
Bug introduced by
The type Robo\Task\Testing\Behat was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type Robo\Task\Base\Exec was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
112
     */
113
    private function configureBehat()
114
    {
115
        $task = $this->taskBehat();
116
        $task->noInteraction()
117
            ->format('progress')
118
            ->colors();
119
120
        if ($this->coverage) {
121
            $task->option('coverage');
122
            $command = $task->getCommand();
123
            $task    = $this->taskExec('phpdbg -qrr '.$command);
124
        } else {
125
            $task->option('tags', '~@coverage');
126
        }
127
128
        return $task;
129
    }
130
131
    /**
132
     * @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Phpspec
0 ignored issues
show
Bug introduced by
The type Robo\Task\Testing\Phpspec was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
133
     */
134
    private function configurePhpSpec()
135
    {
136
        $task = $this->taskPhpspec();
137
        $task->noCodeGeneration()
138
            ->noInteraction()
139
            ->format('dot');
140
141
        if ($this->coverage) {
142
            $task->option('coverage');
143
            $task = $this->taskExec('phpdbg -qrr '.$task->getCommand());
144
        }
145
146
        return $task;
147
    }
148
149
    /**
150
     * @return \Robo\Task\Base\Exec|\Robo\Task\Testing\PHPUnit
0 ignored issues
show
Bug introduced by
The type Robo\Task\Testing\PHPUnit was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
151
     */
152
    private function configurePhpUnit()
0 ignored issues
show
Unused Code introduced by
The method configurePhpUnit() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
153
    {
154
        $task = $this->taskPhpUnit();
155
156
        if ($this->coverage) {
157
            $task = $this->taskExec('phpdbg -qrr '.$task->getCommand());
158
            $task->option('coverage-php', 'build/cov/01-phpunit.cov')
159
                ->option('coverage-html', 'build/phpunit');
160
        }
161
162
        return $task;
163
    }
164
}
165