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 ( eef6d0...962304 )
by Freek
01:16
created

Phpunit::sendDesktopNotification()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 4
nop 1
1
<?php
2
3
namespace Spatie\PhpUnitWatcher\Screens;
4
5
use Spatie\PhpUnitWatcher\Notification;
6
use Spatie\PhpUnitWatcher\Notifier;
7
use Symfony\Component\Process\Process;
8
9
class Phpunit extends Screen
10
{
11
    /** @var array */
12
    protected $options;
13
14
    public function __construct(array $options)
15
    {
16
        $this->options = $options;
17
    }
18
19
    public function draw()
20
    {
21
        $this
22
            ->writeHeader()
23
            ->runTests()
24
            ->displayManual();
25
    }
26
27
    public function registerListeners()
28
    {
29
        $this->terminal->onKeyPress(function ($line) {
30
            $line = strtolower($line);
31
32
            switch ($line) {
33
                case '':
34
                    $this->terminal->refreshScreen();
35
                    break;
36
                case 'a':
37
                    $this->terminal->displayScreen(new Phpunit());
0 ignored issues
show
Bug introduced by
The call to Phpunit::__construct() misses a required argument $options.

This check looks for function calls that miss required arguments.

Loading history...
38
                    break;
39
                case 't':
40
                    $this->terminal->displayScreen(new FilterTestName());
41
                    break;
42
                case 'p':
43
                    $this->terminal->displayScreen(new FilterFileName());
44
                    break;
45
                case 'q':
46
                    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...
47
                    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...
48
            }
49
        });
50
51
        return $this;
52
    }
53
54
    protected function writeHeader()
55
    {
56
        $title = 'Starting PHPUnit';
57
58
        if (! empty($this->options['phpunitArguments'])) {
59
            $title .= " with arguments: `{$this->options['phpunitArguments']}`";
60
        }
61
62
        $this->terminal
63
            ->comment($title)
64
            ->emptyLine();
65
66
        return $this;
67
    }
68
69
    protected function runTests()
70
    {
71
        $result = (new Process("vendor/bin/phpunit {$this->options['phpunitArguments']}"))
72
            ->setTty(true)
73
            ->run(function ($type, $line) {
74
                echo $line;
75
            });
76
77
        $this->sendDesktopNotification($result);
78
79
        return $this;
80
    }
81
82
    protected function displayManual()
83
    {
84
        $this->terminal
85
            ->emptyLine()
86
            ->write('Press a to run all tests.')
87
            ->write('Press t to filter by test name.')
88
            ->write('Press p to filter by file name.')
89
            ->write('Press q to quit the watcher.')
90
            ->write('Press Enter to trigger a test run.');
91
92
        return $this;
93
    }
94
95
    protected function sendDesktopNotification(int $result)
96
    {
97
        $notificationName = $result === 0
98
            ? 'passingTests'
99
            : 'failingTests';
100
101
       if ($this->options['notifications'][$notificationName]) {
102
           Notification::create()->$notificationName();
103
       }
104
    }
105
}
106