1 | <?php |
||
24 | class Enumerator |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * Path to the root directory, where enumeration should start |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $rootDirectory; |
||
33 | |||
34 | /** |
||
35 | * List of additional include paths, should be below rootDirectory |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | private $includePaths; |
||
40 | |||
41 | /** |
||
42 | * List of additional exclude paths, should be below rootDirectory |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | private $excludePaths; |
||
47 | |||
48 | /** |
||
49 | * Initializes an enumerator |
||
50 | * |
||
51 | * @param string $rootDirectory Path to the root directory |
||
52 | * @param array $includePaths List of additional include paths |
||
53 | * @param array $excludePaths List of additional exclude paths |
||
54 | */ |
||
55 | 7 | public function __construct($rootDirectory, array $includePaths = [], array $excludePaths = []) |
|
61 | |||
62 | /** |
||
63 | * Returns an enumerator for files |
||
64 | * |
||
65 | * @return CallbackFilterIterator|RecursiveIteratorIterator|\IteratorIterator|SplFileInfo[] |
||
66 | * @throws UnexpectedValueException |
||
67 | * @throws InvalidArgumentException |
||
68 | * @throws LogicException |
||
69 | */ |
||
70 | 7 | public function enumerate() |
|
103 | |||
104 | private function dumpForAppVeyor($iterator) |
||
112 | |||
113 | /** |
||
114 | * @return array |
||
115 | * @throws UnexpectedValueException |
||
116 | */ |
||
117 | 7 | private function getInPaths() |
|
136 | |||
137 | /** |
||
138 | * @return array |
||
139 | */ |
||
140 | 7 | private function getExcludePaths() |
|
151 | |||
152 | /** |
||
153 | * Returns a filter callback for enumerating files |
||
154 | * |
||
155 | * @return \Closure |
||
156 | */ |
||
157 | public function getFilter() |
||
197 | |||
198 | /** |
||
199 | * Return the real path of the given file |
||
200 | * |
||
201 | * This is used for testing purpose with virtual file system. |
||
202 | * In a vfs the 'realPath' methode will always return false. |
||
203 | * So we have a chance to mock this single function to return different path. |
||
204 | * |
||
205 | * @param SplFileInfo $file |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | protected function getFileFullPath(SplFileInfo $file) |
||
213 | |||
214 | } |
||
215 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.