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
Pull Request — master (#8)
by Casper
01:29
created

Watcher   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 54
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A usePhpunitArguments() 0 6 1
A startWatching() 0 19 3
A clearScreen() 0 4 1
A runTests() 0 8 1
1
<?php
2
3
namespace Spatie\PhpUnitWatcher;
4
5
use Symfony\Component\Finder\Finder;
6
use Symfony\Component\Process\Process;
7
use Yosymfony\ResourceWatcher\ResourceCacheMemory;
8
use Yosymfony\ResourceWatcher\ResourceWatcher;
9
10
class Watcher
11
{
12
    /** @var \Symfony\Component\Finder\Finder */
13
    protected $finder;
14
15
    /** @var $string */
16
    protected $phpunitArguments;
17
18
    public function __construct(Finder $finder)
19
    {
20
        $this->finder = $finder;
21
    }
22
23
    public function usePhpunitArguments(string $arguments)
24
    {
25
        $this->phpunitArguments = $arguments;
26
27
        return $this;
28
    }
29
30
    public function startWatching()
31
    {
32
        $this->runTests();
33
34
        $watcher = new ResourceWatcher(new ResourceCacheMemory());
35
36
        $watcher->setFinder($this->finder);
37
38
        while (true) {
39
            $watcher->findChanges();
40
41
            if ($watcher->hasChanges()) {
42
                $this->clearScreen();
43
                $this->runTests();
44
            }
45
46
            usleep(250000);
47
        }
48
    }
49
50
    protected function clearScreen()
51
    {
52
        passthru("echo '\033\143'");
53
    }
54
55
    protected function runTests()
56
    {
57
        (new Process("vendor/bin/phpunit {$this->phpunitArguments}"))
58
            ->setTty(true)
59
            ->run(function ($type, $line) {
60
                echo $line;
61
            });
62
    }
63
}
64