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.

FilterFileName   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 4
dl 0
loc 86
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A draw() 0 12 1
A registerListeners() 0 26 2
A registerAutocompleter() 0 31 3
A sanitzeOffset() 0 11 6
1
<?php
2
3
namespace Spatie\PhpUnitWatcher\Screens;
4
5
class FilterFileName extends Screen
6
{
7
    public function draw()
8
    {
9
        $this->terminal
10
            ->comment('Pattern mode usage')
11
            ->write('Type a pattern and press Enter to only run tests in the giving path or file.')
12
            ->write('Press Enter with an empty pattern to execute all tests in all files.')
13
            ->emptyLine()
14
            ->comment('Start typing to filter by a test name.')
15
            ->prompt('pattern > ');
16
17
        return $this;
18
    }
19
20
    public function registerListeners()
21
    {
22
        $readline = $this->terminal->getReadline();
23
24
        $this->terminal->on('data', function ($line) {
25
            if ($line == '') {
26
                $this->terminal->goBack();
27
28
                return;
29
            }
30
31
            $phpunitArguments = "{$line}";
32
33
            $phpunitScreen = $this->terminal->getPreviousScreen();
34
35
            $options = $phpunitScreen->options;
0 ignored issues
show
Bug introduced by
The property options does not seem to exist in Spatie\PhpUnitWatcher\Screens\Screen.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
36
37
            $options['phpunit']['arguments'] = $phpunitArguments;
38
39
            $this->terminal->displayScreen(new Phpunit($options));
40
        });
41
42
        $this->registerAutocompleter($readline);
43
44
        return $this;
45
    }
46
47
    protected function registerAutocompleter($readline)
48
    {
49
        $readline->setAutocomplete(function ($word, $startOffset, $endOffset) use ($readline) {
50
            $input = $readline->getInput();
51
52
            $paths = glob("$word*", GLOB_MARK);
53
54
            if (empty($paths)) {
55
                return;
56
            }
57
58
            if (count($paths) > 1) {
59
                $this->terminal->getStdio()->write(implode('  ', $paths)."\n");
60
61
                return;
62
            }
63
64
            $path = $paths[0];
65
66
            $lineStart = mb_substr($input, 0, $startOffset);
67
            $lineEnd = mb_substr($input, $endOffset);
68
69
            $path = $this->sanitzeOffset($startOffset, $path, $input);
70
71
            $newInput = $lineStart.$path.$lineEnd;
72
73
            $readline->setInput($newInput);
74
75
            $readline->moveCursorTo($startOffset + mb_strlen($path));
76
        });
77
    }
78
79
    protected function sanitzeOffset($startOffset, $path, $input): string
80
    {
81
        if ($startOffset > 0 && mb_strlen($path) > 1 && mb_substr($path, -1) != DIRECTORY_SEPARATOR) {
82
            $previousChar = mb_substr($input, $startOffset - 1, 1);
83
            if ($previousChar === '"' || $previousChar === '\'') {
84
                $path .= $previousChar;
85
            }
86
        }
87
88
        return $path;
89
    }
90
}
91