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 ( 6865bc...4840e2 )
by Freek
06:21 queued 05:00
created

Phpunit::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Spatie\PhpUnitWatcher\Screens;
4
5
use Symfony\Component\Process\Process;
6
7
class Phpunit extends Screen
8
{
9
    /** @var string */
10
    protected $phpunitArguments;
11
12
    public function __construct(string $phpunitArguments = '')
13
    {
14
        $this->phpunitArguments = $phpunitArguments;
15
    }
16
17
    public function draw()
18
    {
19
        $this
20
            ->writeHeader()
21
            ->runTests()
22
            ->displayManual();
23
    }
24
25
    public function registerListeners()
26
    {
27
        $this->terminal->onKeyPress(function ($line) {
28
            $line = strtolower($line);
29
30
            switch ($line) {
31
                case '':
32
                    $this->terminal->refreshScreen();
33
                    break;
34
                case 'a':
35
                    $this->terminal->displayScreen(new Phpunit());
36
                    break;
37
                case 't':
38
                    $this->terminal->displayScreen(new FilterTestName());
39
                    break;
40
                case 'p':
41
                    $this->terminal->displayScreen(new FilterFileName());
42
                    break;
43
                case 'q':
44
                    die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method registerListeners() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
45
                    break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
46
            }
47
        });
48
49
        return $this;
50
    }
51
52
    protected function writeHeader()
53
    {
54
        $title = 'Starting PHPUnit';
55
56
        if (!empty($this->phpunitArguments)) {
57
            $title .= " with arguments: `{$this->phpunitArguments}`";
58
        }
59
60
        $this->terminal
61
            ->comment($title)
62
            ->emptyLine();
63
64
        return $this;
65
    }
66
67
    protected function runTests()
68
    {
69
        (new Process("vendor/bin/phpunit {$this->phpunitArguments}"))
70
            ->setTty(true)
71
            ->run(function ($type, $line) {
72
                echo $line;
73
            });
74
75
        return $this;
76
    }
77
78
    protected function displayManual()
79
    {
80
        $this->terminal
81
            ->emptyLine()
82
            ->write('Press a to run all tests.')
83
            ->write('Press t to filter by a test name.')
84
            ->write('Press p to filter by a file name.')
85
            ->write('Press q to quit the watcher.')
86
            ->write('Press Enter to trigger a test run.');
87
88
        return $this;
89
    }
90
}
91