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.

Exporter   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A cleanBeforeExport() 0 6 1
A crawl() 0 6 1
A paths() 0 8 2
A urls() 0 10 2
A includeFiles() 0 6 1
A excludeFilePatterns() 0 6 1
A export() 0 26 5
1
<?php
2
3
namespace Spatie\Export;
4
5
use Illuminate\Contracts\Bus\Dispatcher;
6
use Illuminate\Contracts\Routing\UrlGenerator;
7
use Illuminate\Support\Str;
8
use Spatie\Export\Jobs\CleanDestination;
9
use Spatie\Export\Jobs\CrawlSite;
10
use Spatie\Export\Jobs\ExportPath;
11
use Spatie\Export\Jobs\IncludeFile;
12
13
class Exporter
14
{
15
    /** @var \Illuminate\Contracts\Bus\Dispatcher */
16
    protected $dispatcher;
17
18
    /** @var UrlGenerator */
19
    protected $urlGenerator;
20
21
    /** @var bool */
22
    protected $cleanBeforeExport = false;
23
24
    /** @var bool */
25
    protected $crawl = false;
26
27
    /** @var string[] */
28
    protected $paths = [];
29
30
    /** @var string[] */
31
    protected $includeFiles = [];
32
33
    /** @var string[] */
34
    protected $excludeFilePatterns = [];
35
36
    public function __construct(Dispatcher $dispatcher, UrlGenerator $urlGenerator)
37
    {
38
        $this->dispatcher = $dispatcher;
39
        $this->urlGenerator = $urlGenerator;
40
    }
41
42
    public function cleanBeforeExport(bool $cleanBeforeExport): self
43
    {
44
        $this->cleanBeforeExport = $cleanBeforeExport;
45
46
        return $this;
47
    }
48
49
    public function crawl(bool $crawl): self
50
    {
51
        $this->crawl = $crawl;
52
53
        return $this;
54
    }
55
56
    public function paths(...$paths): self
57
    {
58
        $paths = is_array($paths[0]) ? $paths[0] : $paths;
59
60
        $this->paths = array_merge($this->paths, $paths);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($this->paths, $paths) of type array is incompatible with the declared type array<integer,string> of property $paths.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
62
        return $this;
63
    }
64
65
    public function urls(...$urls): self
66
    {
67
        $urls = is_array($urls[0]) ? $urls[0] : $urls;
68
69
        $this->paths(array_map(function (string $url): string {
70
            return Str::replaceFirst($this->urlGenerator->to('/'), '', $url);
71
        }, $urls));
72
73
        return $this;
74
    }
75
76
    public function includeFiles(array $includeFiles): self
77
    {
78
        $this->includeFiles = array_merge($this->includeFiles, $includeFiles);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($this->includeFiles, $includeFiles) of type array is incompatible with the declared type array<integer,string> of property $includeFiles.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
79
80
        return $this;
81
    }
82
83
    public function excludeFilePatterns(array $excludeFilePatterns): self
84
    {
85
        $this->excludeFilePatterns = array_merge($this->excludeFilePatterns, $excludeFilePatterns);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($this->exclu..., $excludeFilePatterns) of type array is incompatible with the declared type array<integer,string> of property $excludeFilePatterns.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
86
87
        return $this;
88
    }
89
90
    public function export()
91
    {
92
        if ($this->cleanBeforeExport) {
93
            $this->dispatcher->dispatchNow(
94
                new CleanDestination()
95
            );
96
        }
97
98
        if ($this->crawl) {
99
            $this->dispatcher->dispatchNow(
100
                new CrawlSite()
101
            );
102
        }
103
104
        foreach ($this->paths as $path) {
105
            $this->dispatcher->dispatchNow(
106
                new ExportPath($path)
107
            );
108
        }
109
110
        foreach ($this->includeFiles as $source => $target) {
111
            $this->dispatcher->dispatchNow(
112
                new IncludeFile($source, $target, $this->excludeFilePatterns)
113
            );
114
        }
115
    }
116
}
117