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.

WatcherFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\PhpUnitWatcher;
4
5
use InvalidArgumentException;
6
use Symfony\Component\Finder\Finder;
7
8
class WatcherFactory
9
{
10
    public static function create(array $options = []): array
11
    {
12
        $options = static::mergeWithDefaultOptions($options);
13
14
        if (empty($options['watch']['directories'])) {
15
            throw new InvalidArgumentException(
16
                'The watch directories do not exist. Make sure you are running the watcher from '.
17
                'the root of your project, or create a custom config file.'
18
            );
19
        }
20
21
        $finder = (new Finder())
22
            ->ignoreDotFiles(false)
23
            ->ignoreVCS(false)
24
            ->name($options['watch']['fileMask'])
25
            ->files()
26
            ->in($options['watch']['directories']);
27
28
        $watcher = new Watcher($finder, $options);
29
30
        return [$watcher, $options];
31
    }
32
33
    protected static function mergeWithDefaultOptions(array $options): array
34
    {
35
        $options = array_merge([
36
37
            'watch' => [
38
                'directories' => [
39
                    'app',
40
                    'src',
41
                    'tests',
42
                ],
43
                'fileMask' => '*.php',
44
            ],
45
            'notifications' => [
46
                'passingTests' => true,
47
                'failingTests' => true,
48
            ],
49
            'hideManual' => false,
50
        ], $options);
51
52
        $options['watch']['directories'] = array_map(function ($directory) {
53
            return getcwd()."/{$directory}";
54
        }, $options['watch']['directories']);
55
56
        $options['watch']['directories'] = array_filter($options['watch']['directories'], function ($directory) {
57
            return file_exists($directory);
58
        });
59
60
        return $options;
61
    }
62
}
63