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 (#13)
by Freek
01:20
created

WatcherCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 5
dl 0
loc 72
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A execute() 0 10 1
A determineOptions() 0 8 1
A getOptionsConfigFile() 0 16 3
A getOptionsFromConfigFile() 0 10 2
A displayOptions() 0 12 1
1
<?php
2
3
namespace Spatie\PhpUnitWatcher;
4
5
use Symfony\Component\Yaml\Yaml;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Style\SymfonyStyle;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use function var_dump;
12
13
class WatcherCommand extends Command
14
{
15
    const PHPUNIT_WATCH_CONFIG_FILENAME = "/.phpunit-watcher.yml";
16
17
    protected function configure()
18
    {
19
        $this->setName('watch')
20
            ->setDescription('Rerun PHPUnit tests when source code changes.')
21
            ->addArgument('phpunit-options', InputArgument::OPTIONAL, 'Options passed to phpunit');
22
    }
23
24
    protected function execute(InputInterface $input, OutputInterface $output)
25
    {
26
        $options = $this->determineOptions($input);
27
28
        list($watcher, $options) = WatcherFactory::create($options);
29
30
        $this->displayOptions($options, $input, $output);
31
32
        $watcher->startWatching();
33
    }
34
35
    protected function determineOptions(InputInterface $input): array
36
    {
37
        $options = $this->getOptionsFromConfigFile();
38
39
        $options['phpunitArguments'] = trim($input->getArgument('phpunit-options'), "'");
40
41
        return $options;
42
    }
43
44
    protected function getOptionsConfigFile()
45
    {
46
        $configPath = getcwd();
47
        $configFile = $configPath . self::PHPUNIT_WATCH_CONFIG_FILENAME;
48
49
        while (! file_exists($configFile)):
50
            $configPath = dirname($configPath);
51
            $configFile = $configPath . self::PHPUNIT_WATCH_CONFIG_FILENAME;
52
            if ($configPath === '/') {
53
                $configFile = self::PHPUNIT_WATCH_CONFIG_FILENAME;
54
                break;
55
            }
56
        endwhile;
57
58
        return $configFile;
59
    }
60
61
    protected function getOptionsFromConfigFile(): array
62
    {
63
        $configFile = $this->getOptionsConfigFile();
64
65
        if (! file_exists($configFile)) {
66
            return [];
67
        }
68
69
        return Yaml::parse(file_get_contents($configFile));
70
    }
71
72
    protected function displayOptions(array $options, InputInterface $input, OutputInterface $output)
73
    {
74
        $output = new SymfonyStyle($input, $output);
75
76
        $output->title('PHPUnit Watcher');
77
78
        $output->text("Tests will be rerun when {$options['watch']['fileMask']} files are modified in the following directories:\n");
79
80
        $output->listing($options['watch']['directories']);
81
82
        $output->newLine();
83
    }
84
}
85