1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Infrastructure\Parser; |
14
|
|
|
|
15
|
|
|
use Flyfinder\Path; |
16
|
|
|
use Flyfinder\Specification\AndSpecification; |
17
|
|
|
use Flyfinder\Specification\HasExtension; |
18
|
|
|
use Flyfinder\Specification\InPath; |
19
|
|
|
use Flyfinder\Specification\IsHidden; |
20
|
|
|
use Flyfinder\Specification\NotSpecification; |
21
|
|
|
use Flyfinder\Specification\OrSpecification; |
22
|
|
|
use Flyfinder\Specification\SpecificationInterface; |
23
|
|
|
use phpDocumentor\Infrastructure\SpecificationFactory as FactoryInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Factory class to build Specification used by FlyFinder when reading files to process. |
27
|
|
|
*/ |
28
|
|
|
final class SpecificationFactory implements FactoryInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Creates a SpecificationInterface object based on the ignore and extension parameters. |
32
|
|
|
* |
33
|
|
|
* @param array $paths |
34
|
|
|
* @param array $ignore |
35
|
|
|
* @param array $extensions |
36
|
|
|
* @return SpecificationInterface |
37
|
|
|
*/ |
38
|
|
|
public function create(array $paths, array $ignore, array $extensions): SpecificationInterface |
39
|
|
|
{ |
40
|
|
|
$pathSpec = null; |
41
|
|
|
foreach ($paths as $path) { |
42
|
|
|
$pathSpec = $this->orSpec($this->inPath($path), $pathSpec); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$ignoreSpec = null; |
46
|
|
|
if (isset($ignore['paths'])) { |
47
|
|
|
foreach ($ignore['paths'] as $path) { |
48
|
|
|
$ignoreSpec = $this->orSpec($this->inPath($path), $ignoreSpec); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (isset($ignore['hidden']) && $ignore['hidden'] === true) { |
53
|
|
|
$ignoreSpec = $this->orSpec(new IsHidden(), $ignoreSpec); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $this->andSpec( |
57
|
|
|
$pathSpec, |
58
|
|
|
$this->andSpec(new HasExtension($extensions), $this->notSpec($ignoreSpec)) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Will return an OrSpecification when $or and $spec are both not null. |
64
|
|
|
* |
65
|
|
|
* @param SpecificationInterface $or |
66
|
|
|
* @param SpecificationInterface|null $spec |
67
|
|
|
* @return OrSpecification|SpecificationInterface |
68
|
|
|
*/ |
69
|
|
|
private function orSpec(SpecificationInterface $or, SpecificationInterface $spec = null): SpecificationInterface |
70
|
|
|
{ |
71
|
|
|
if ($spec === null) { |
72
|
|
|
return $or; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return new OrSpecification($spec, $or); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Creates an InPath specification. |
80
|
|
|
* |
81
|
|
|
* @param string $path |
82
|
|
|
* @return InPath |
83
|
|
|
*/ |
84
|
|
|
private function inPath($path): InPath |
85
|
|
|
{ |
86
|
|
|
return new InPath(new Path($path)); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
private function notSpec(SpecificationInterface $ignoreSpec = null) |
90
|
|
|
{ |
91
|
|
|
if ($ignoreSpec === null) { |
92
|
|
|
return null; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return new NotSpecification($ignoreSpec); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
private function andSpec(SpecificationInterface $spec = null, SpecificationInterface $spec2 = null) |
99
|
|
|
{ |
100
|
|
|
if ($spec === null) { |
101
|
|
|
return $spec2; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if ($spec2 === null) { |
105
|
|
|
return $spec; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return new AndSpecification($spec, $spec2); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: