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.
Passed
Pull Request — master (#8)
by Brent
01:44
created

DirectoryParser   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 38
dl 0
loc 104
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getParsed() 0 24 4
A __construct() 0 3 1
A summarize() 0 13 3
A setExtensions() 0 5 1
A onFileParsed() 0 5 1
A getExtensionsRegex() 0 7 1
A onStartParsing() 0 5 1
A setExtensionsFromString() 0 8 1
1
<?php
2
3
namespace Spatie\CodeOutline\Parser;
4
5
use Closure;
6
use Spatie\CodeOutline\Page;
7
use Symfony\Component\Finder\Finder;
8
9
class DirectoryParser implements Parser
10
{
11
    /** @var string */
12
    protected $path;
13
14
    /** @var array */
15
    protected $extensions = ['php'];
16
17
    /** @var Closure */
18
    protected $initListener;
19
20
    /** @var Closure */
21
    protected $progressListener;
22
23
    public function __construct(string $path)
24
    {
25
        $this->path = $path;
26
    }
27
28
    public function setExtensions(array $extensions): self
29
    {
30
        $this->extensions = $extensions;
31
32
        return $this;
33
    }
34
35
    public function setExtensionsFromString(string $extensionsString): self
36
    {
37
        $extensions = explode(',', $extensionsString);
38
39
        return $this->setExtensions(
40
            array_map(function (string $extension) {
41
                return str_replace(['*', '.'], '', $extension);
42
            }, $extensions)
43
        );
44
    }
45
46
    public function onStartParsing(Closure $initListener): self
47
    {
48
        $this->initListener = $initListener;
49
50
        return $this;
51
    }
52
53
    public function onFileParsed(Closure $progressListener): self
54
    {
55
        $this->progressListener = $progressListener;
56
57
        return $this;
58
    }
59
60
    public function getParsed(): Page
61
    {
62
        $parsedFiles = [];
63
64
        $files = Finder::create()->files()->in($this->path)->name($this->getExtensionsRegex());
65
66
        if ($this->initListener) {
67
            call_user_func_array($this->initListener, [$files->count()]);
68
        }
69
70
        /** @var \Symfony\Component\Finder\SplFileInfo $file */
71
        foreach ($files as $file) {
72
            $fileParser = new FileParser($file->getRealPath());
73
74
            $parsedFiles[] = $fileParser->getParsed();
75
76
            if (!$this->progressListener) {
77
                continue;
78
            }
79
80
            call_user_func($this->progressListener);
81
        }
82
83
        return $this->summarize($parsedFiles);
84
    }
85
86
    /**
87
     * @param \Spatie\CodeOutline\Page[] $pages
88
     *
89
     * @return \Spatie\CodeOutline\Page
90
     */
91
    protected function summarize(array $pages): Page
92
    {
93
        $summarizedPage = new Page();
94
95
        foreach ($pages as $page) {
96
            foreach ($page as $lineNumber => $line) {
97
                $summarizedLine = $summarizedPage[$lineNumber] ?? new Line();
0 ignored issues
show
Bug introduced by
The type Spatie\CodeOutline\Parser\Line was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
98
99
                $summarizedPage[$lineNumber] = $summarizedLine->merge($line);
100
            }
101
        }
102
103
        return $summarizedPage;
104
    }
105
106
    protected function getExtensionsRegex(): string
107
    {
108
        $query = implode('|', array_map(function ($extension) {
109
            return "\.{$extension}\$";
110
        }, $this->extensions));
111
112
        return "/{$query}/";
113
    }
114
}
115