Total Lines | 54 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
126 | 9 | private function createClassmapIterator( |
|
127 | iterable $classmap, |
||
128 | iterable $exclude = [] |
||
129 | ): Iterator { |
||
130 | 9 | $files = new AppendIterator(); |
|
131 | |||
132 | 9 | foreach ($classmap as $directory) { |
|
133 | 5 | if (!is_dir($directory)) { |
|
134 | 1 | continue; |
|
135 | } |
||
136 | |||
137 | 5 | $files->append( |
|
138 | 5 | new RecursiveIteratorIterator( |
|
139 | 5 | new RecursiveDirectoryIterator($directory) |
|
140 | ) |
||
141 | ); |
||
142 | } |
||
143 | |||
144 | return new class ($files, $this->preparePattern(...$exclude)) extends FilterIterator { |
||
145 | /** @var string|null */ |
||
146 | private $excludePattern; |
||
147 | |||
148 | /** |
||
149 | * Constructor. |
||
150 | * |
||
151 | * @param Iterator $iterator |
||
152 | * @param string|null $excludePattern |
||
153 | */ |
||
154 | 9 | public function __construct( |
|
155 | Iterator $iterator, |
||
156 | ?string $excludePattern |
||
157 | ) { |
||
158 | 9 | $this->excludePattern = $excludePattern; |
|
159 | |||
160 | 9 | parent::__construct($iterator); |
|
161 | 9 | } |
|
162 | |||
163 | /** |
||
164 | * Check whether the current element of the iterator is acceptable. |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | 5 | public function accept(): bool |
|
169 | { |
||
170 | /** @var SplFileInfo $file */ |
||
171 | 5 | $file = $this->getInnerIterator()->current(); |
|
172 | |||
173 | return ( |
||
174 | 5 | $file->isFile() |
|
175 | && ( |
||
176 | 5 | $this->excludePattern === null |
|
177 | 1 | ?: !preg_match( |
|
178 | 1 | $this->excludePattern, |
|
179 | 5 | str_replace('\\', '/', $file->getRealPath()) |
|
180 | ) |
||
215 |