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 ( 3e7fd9...11f6e5 )
by Freek
03:05 queued 01:42
created

WatcherCommand::getConfigFileLocation()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 0
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
12
class WatcherCommand extends Command
13
{
14
    const PHPUNIT_WATCH_CONFIG_FILENAME = "/.phpunit-watcher.yml";
15
16
    protected function configure()
17
    {
18
        $this->setName('watch')
19
            ->setDescription('Rerun PHPUnit tests when source code changes.')
20
            ->addArgument('phpunit-options', InputArgument::OPTIONAL, 'Options passed to phpunit');
21
    }
22
23
    protected function execute(InputInterface $input, OutputInterface $output)
24
    {
25
        $options = $this->determineOptions($input);
26
27
        list($watcher, $options) = WatcherFactory::create($options);
28
29
        $this->displayOptions($options, $input, $output);
30
31
        $watcher->startWatching();
32
    }
33
34
    protected function determineOptions(InputInterface $input): array
35
    {
36
        $options = $this->getOptionsFromConfigFile();
37
38
        $options['phpunitArguments'] = trim($input->getArgument('phpunit-options'), "'");
39
40
        return $options;
41
    }
42
43
    protected function getOptionsFromConfigFile(): array
44
    {
45
        $configFile = $this->getConfigFileLocation();
46
47
        if (! file_exists($configFile)) {
48
            return [];
49
        }
50
51
        return Yaml::parse(file_get_contents($configFile));
52
    }
53
54
    protected function getConfigFileLocation()
55
    {
56
        $configName = '.phpunit-watcher.yml';
57
58
        $configDirectory = getcwd();
59
60
        while(is_dir($configDirectory)) {
61
            $configFullPath = "{$configDirectory}/{$configName}";
62
63
            if (file_exists($configFullPath)) {
64
                return $configFullPath;
65
            }
66
67
            if ($configDirectory === DIRECTORY_SEPARATOR) {
68
                return;
69
            }
70
            $configDirectory = dirname($configDirectory);
71
        };
72
    }
73
74
    protected function displayOptions(array $options, InputInterface $input, OutputInterface $output)
75
    {
76
        $output = new SymfonyStyle($input, $output);
77
78
        $output->title('PHPUnit Watcher');
79
80
        $output->text("Tests will be rerun when {$options['watch']['fileMask']} files are modified in");
81
82
        $output->listing($options['watch']['directories']);
83
84
        $output->newLine();
85
    }
86
}
87