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 ( f34d69...755836 )
by Sebastian
02:33
created

IncludeFiles   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 67
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 10 3
A exportIncludedFile() 0 10 2
A exportIncludedDirectory() 0 19 3
A shouldExclude() 0 10 3
1
<?php
2
3
namespace Spatie\Export\Jobs;
4
5
use RecursiveIteratorIterator;
6
use RecursiveDirectoryIterator;
7
use Spatie\Export\Destination;
8
9
class IncludeFiles
10
{
11
    /** @var string[] */
12
    protected $includeFiles;
13
14
    /** @var string[] */
15
    protected $excludeFilePatterns;
16
17
    public function __construct(array $includeFiles, array $excludeFilePatterns)
18
    {
19
        $this->includeFiles = $includeFiles;
20
        $this->excludeFilePatterns = $excludeFilePatterns;
21
    }
22
23
    public function handle(Destination $destination)
24
    {
25
        foreach ($this->includeFiles as $source => $target) {
26
            if (is_file($source)) {
27
                $this->exportIncludedFile($source, $target, $destination);
28
            } else {
29
                $this->exportIncludedDirectory($source, $target, $destination);
30
            }
31
        }
32
    }
33
34
    protected function exportIncludedFile(string $source, string $target, Destination $destination)
35
    {
36
        if ($this->shouldExclude($source)) {
37
            return;
38
        }
39
40
        $target = '/'.ltrim($target, '/');
41
42
        $destination->write($target, file_get_contents($source));
43
    }
44
45
    protected function exportIncludedDirectory(string $source, string $target, Destination $destination)
46
    {
47
        $iterator = new RecursiveIteratorIterator(
48
            new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
49
            RecursiveIteratorIterator::SELF_FIRST
50
        );
51
52
        foreach ($iterator as $item) {
53
            if ($item->isDir()) {
54
                continue;
55
            }
56
57
            $this->exportIncludedFile(
58
                $item->getPathname(),
59
                $target.'/'.$iterator->getSubPathName(),
60
                $destination
61
            );
62
        }
63
    }
64
65
    protected function shouldExclude(string $source): bool
66
    {
67
        foreach ($this->excludeFilePatterns as $pattern) {
68
            if (preg_match($pattern, $source)) {
69
                return true;
70
            }
71
        }
72
73
        return false;
74
    }
75
}
76