These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | /** |
||
5 | * This file is part of phpDocumentor. |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | * |
||
10 | * @author Mike van Riel <[email protected]> |
||
11 | * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
||
12 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
13 | * @link http://phpdoc.org |
||
14 | */ |
||
15 | |||
16 | namespace phpDocumentor\Parser; |
||
17 | |||
18 | use Flyfinder\Path; |
||
19 | use Flyfinder\Specification\AndSpecification; |
||
20 | use Flyfinder\Specification\HasExtension; |
||
21 | use Flyfinder\Specification\InPath; |
||
22 | use Flyfinder\Specification\IsHidden; |
||
23 | use Flyfinder\Specification\NotSpecification; |
||
24 | use Flyfinder\Specification\OrSpecification; |
||
25 | use Flyfinder\Specification\SpecificationInterface; |
||
26 | use phpDocumentor\Parser\SpecificationFactoryInterface as FactoryInterface; |
||
27 | |||
28 | /** |
||
29 | * Factory class to build Specification used by FlyFinder when reading files to process. |
||
30 | */ |
||
31 | final class SpecificationFactory implements FactoryInterface |
||
32 | { |
||
33 | /** |
||
34 | * Creates a SpecificationInterface object based on the ignore and extension parameters. |
||
35 | * |
||
36 | 3 | * @var (\phpDocumentor\Path|string)[] $paths |
|
37 | * @var (\phpDocumentor\Path|string)[] $ignore |
||
38 | 3 | * @var string[] $extensions |
|
39 | 3 | */ |
|
40 | 3 | public function create(array $paths, array $ignore, array $extensions): SpecificationInterface |
|
41 | { |
||
42 | $pathSpec = null; |
||
43 | 3 | foreach ($paths as $path) { |
|
44 | 3 | if ($pathSpec === null) { |
|
45 | 2 | $pathSpec = $this->inPath((string) $path); |
|
46 | 1 | continue; |
|
47 | } |
||
48 | |||
49 | $pathSpec = $this->orSpec($this->inPath($path), $pathSpec); |
||
50 | 3 | } |
|
51 | 1 | ||
52 | $ignoreSpec = null; |
||
53 | foreach ($ignore['paths'] ?? [] as $path) { |
||
0 ignored issues
–
show
|
|||
54 | 3 | if ($ignoreSpec === null) { |
|
55 | 3 | $ignoreSpec = $this->inPath((string) $path); |
|
56 | 3 | continue; |
|
57 | } |
||
58 | |||
59 | $ignoreSpec = $this->orSpec($this->inPath((string) $path), $ignoreSpec); |
||
60 | } |
||
61 | |||
62 | if (($ignore['hidden'] ?? false) === true) { |
||
63 | $ignoreSpec = $ignoreSpec === null |
||
64 | ? new IsHidden() |
||
65 | : $this->orSpec(new IsHidden(), $ignoreSpec); |
||
66 | 3 | } |
|
67 | |||
68 | 3 | $result = new HasExtension($extensions); |
|
69 | 3 | if ($ignoreSpec !== null) { |
|
70 | $result = $this->andSpec($result, $this->notSpec($ignoreSpec)); |
||
71 | } |
||
72 | 1 | if ($pathSpec !== null) { |
|
73 | $result = $this->andSpec($pathSpec, $result); |
||
74 | } |
||
75 | |||
76 | return $result; |
||
77 | } |
||
78 | |||
79 | private function inPath(string $path): InPath |
||
80 | 3 | { |
|
81 | return new InPath(new Path((string) $path)); |
||
82 | 3 | } |
|
83 | |||
84 | private function orSpec(SpecificationInterface $or, SpecificationInterface $spec): SpecificationInterface |
||
85 | 3 | { |
|
86 | return new OrSpecification($spec, $or); |
||
87 | 3 | } |
|
88 | 1 | ||
89 | private function notSpec(SpecificationInterface $ignoreSpec): SpecificationInterface |
||
90 | { |
||
91 | 2 | return new NotSpecification($ignoreSpec); |
|
92 | } |
||
93 | |||
94 | 3 | private function andSpec(SpecificationInterface $spec, SpecificationInterface $spec2): SpecificationInterface |
|
95 | { |
||
96 | 3 | return new AndSpecification($spec, $spec2); |
|
97 | } |
||
98 | } |
||
99 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.