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 ( ebd338...7ee525 )
by Freek
01:18
created

Watcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 8
dl 0
loc 66
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A startWatching() 0 22 3
A buildStdio() 0 17 2
1
<?php
2
3
namespace Spatie\PhpUnitWatcher;
4
5
use Clue\React\Stdio\Stdio;
6
use React\EventLoop\Factory;
7
use React\Stream\ThroughStream;
8
use Symfony\Component\Finder\Finder;
9
use Spatie\PhpUnitWatcher\Screens\Phpunit;
10
use Yosymfony\ResourceWatcher\ResourceWatcher;
11
use Yosymfony\ResourceWatcher\ResourceCacheMemory;
12
13
class Watcher
14
{
15
    /** @var \Symfony\Component\Finder\Finder */
16
    protected $finder;
17
18
    /** @var \React\EventLoop\LibEventLoop */
19
    protected $loop;
20
21
    /** @var \Spatie\PhpUnitWatcher\Terminal */
22
    protected $terminal;
23
24
    /** @var array */
25
    protected $options;
26
27
    public function __construct(Finder $finder, array $options)
28
    {
29
        $this->finder = $finder;
30
31
        $this->loop = Factory::create();
0 ignored issues
show
Documentation Bug introduced by
It seems like \React\EventLoop\Factory::create() of type object<React\EventLoop\LoopInterface> is incompatible with the declared type object<React\EventLoop\LibEventLoop> of property $loop.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
33
        $this->terminal = new Terminal($this->buildStdio());
34
35
        $this->options = $options;
36
    }
37
38
    public function startWatching()
39
    {
40
        $this->terminal->displayScreen(new Phpunit($this->options), false);
41
42
        $watcher = new ResourceWatcher(new ResourceCacheMemory());
43
44
        $watcher->setFinder($this->finder);
45
46
        $this->loop->addPeriodicTimer(1 / 4, function () use ($watcher) {
47
            if (! $this->terminal->isDisplayingScreen(Phpunit::class)) {
48
                return;
49
            }
50
51
            $watcher->findChanges();
52
53
            if ($watcher->hasChanges()) {
54
                $this->terminal->refreshScreen();
55
            }
56
        });
57
58
        $this->loop->run();
59
    }
60
61
    protected function buildStdio()
62
    {
63
        $output = null;
64
65
        if (OS::isOnWindows()) {
66
            // Interaction on windows is currently not supported
67
            fclose(STDIN);
68
69
            // Simple fix for windows compatibility since we don't write a lot of data at once
70
            // https://github.com/clue/reactphp-stdio/issues/83#issuecomment-546678609
71
            $output = new ThroughStream(static function ($data) {
72
                echo $data;
73
            });
74
        }
75
76
        return new Stdio($this->loop, null, $output);
77
    }
78
}
79