Passed
Push — master ( bd479f...f6e659 )
by Patrick
03:20 queued 11s
created

FlatClassSet::excludePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Architecture;
13
14
use Arkitect\ClassSet as ArkitectClassSet;
15
use Arkitect\Glob;
16
use Symfony\Component\Finder\Finder;
17
18
class FlatClassSet extends ArkitectClassSet
19
{
20
    private string $directory;
21
22
    private array $exclude;
23
24
    private function __construct(string $directory)
25
    {
26
        $this->directory = $directory;
27
        $this->exclude = [];
28
    }
29
30
    public function excludePath(string $pattern): self
31
    {
32
        $this->exclude[] = Glob::toRegex($pattern);
33
34
        return $this;
35
    }
36
37
    public static function fromDir(string $directory): self
38
    {
39
        return new self($directory);
40
    }
41
42
    public function getDir(): string
43
    {
44
        return $this->directory;
45
    }
46
47
    public function getIterator()
48
    {
49
        $finder = (new Finder())
50
            ->files()
51
            ->in($this->directory)
52
            ->name('*.php')
53
            ->sortByName()
54
            ->depth('< 2')
55
            ->followLinks()
56
            ->ignoreUnreadableDirs(true)
57
            ->ignoreVCS(true)
58
        ;
59
60
        if ($this->exclude) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->exclude of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
61
            $finder->notPath($this->exclude);
62
        }
63
64
        return $finder;
65
    }
66
}
67