Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 60029a6

Browse files
committed
Move RecursiveDirectoryFilterIterator class from Manager file
1 parent aeba9d2 commit 60029a6

File tree

2 files changed

+90
-88
lines changed

2 files changed

+90
-88
lines changed

src/Manager.php

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -166,91 +166,3 @@ protected function getFilesFromPaths(array $paths, array $extensions, array $exc
166166
return $files;
167167
}
168168
}
169-
170-
class RecursiveDirectoryFilterIterator extends \RecursiveFilterIterator
171-
{
172-
/** @var \RecursiveDirectoryIterator */
173-
private $iterator;
174-
175-
/** @var array */
176-
private $excluded = array();
177-
178-
/**
179-
* @param \RecursiveDirectoryIterator $iterator
180-
* @param array $excluded
181-
*/
182-
public function __construct(\RecursiveDirectoryIterator $iterator, array $excluded)
183-
{
184-
parent::__construct($iterator);
185-
$this->iterator = $iterator;
186-
$this->excluded = array_map(array($this, 'getPathname'), $excluded);
187-
}
188-
189-
/**
190-
* (PHP 5 &gt;= 5.1.0)<br/>
191-
* Check whether the current element of the iterator is acceptable
192-
*
193-
* @link http://php.net/manual/en/filteriterator.accept.php
194-
* @return bool true if the current element is acceptable, otherwise false.
195-
*/
196-
public function accept()
197-
{
198-
$current = $this->current()->getPathname();
199-
$current = $this->normalizeDirectorySeparator($current);
200-
201-
if ('.' . DIRECTORY_SEPARATOR !== $current[0] . $current[1]) {
202-
$current = '.' . DIRECTORY_SEPARATOR . $current;
203-
}
204-
205-
return !in_array($current, $this->excluded);
206-
}
207-
208-
/**
209-
* (PHP 5 &gt;= 5.1.0)<br/>
210-
* Check whether the inner iterator's current element has children
211-
*
212-
* @link http://php.net/manual/en/recursivefilteriterator.haschildren.php
213-
* @return bool true if the inner iterator has children, otherwise false
214-
*/
215-
public function hasChildren()
216-
{
217-
return $this->iterator->hasChildren();
218-
}
219-
220-
/**
221-
* (PHP 5 &gt;= 5.1.0)<br/>
222-
* Return the inner iterator's children contained in a RecursiveFilterIterator
223-
*
224-
* @link http://php.net/manual/en/recursivefilteriterator.getchildren.php
225-
* @return \RecursiveFilterIterator containing the inner iterator's children.
226-
*/
227-
public function getChildren()
228-
{
229-
return new self($this->iterator->getChildren(), $this->excluded);
230-
}
231-
232-
/**
233-
* @param string $file
234-
* @return string
235-
*/
236-
private function getPathname($file)
237-
{
238-
$file = $this->normalizeDirectorySeparator($file);
239-
240-
if ('.' . DIRECTORY_SEPARATOR !== $file[0] . $file[1]) {
241-
$file = '.' . DIRECTORY_SEPARATOR . $file;
242-
}
243-
244-
$directoryFile = new \SplFileInfo($file);
245-
return $directoryFile->getPathname();
246-
}
247-
248-
/**
249-
* @param string $file
250-
* @return string
251-
*/
252-
private function normalizeDirectorySeparator($file)
253-
{
254-
return str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $file);
255-
}
256-
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
namespace JakubOnderka\PhpParallelLint;
3+
4+
class RecursiveDirectoryFilterIterator extends \RecursiveFilterIterator
5+
{
6+
/** @var \RecursiveDirectoryIterator */
7+
private $iterator;
8+
9+
/** @var array */
10+
private $excluded = array();
11+
12+
/**
13+
* @param \RecursiveDirectoryIterator $iterator
14+
* @param array $excluded
15+
*/
16+
public function __construct(\RecursiveDirectoryIterator $iterator, array $excluded)
17+
{
18+
parent::__construct($iterator);
19+
$this->iterator = $iterator;
20+
$this->excluded = array_map(array($this, 'getPathname'), $excluded);
21+
}
22+
23+
/**
24+
* (PHP 5 &gt;= 5.1.0)<br/>
25+
* Check whether the current element of the iterator is acceptable
26+
*
27+
* @link http://php.net/manual/en/filteriterator.accept.php
28+
* @return bool true if the current element is acceptable, otherwise false.
29+
*/
30+
public function accept()
31+
{
32+
$current = $this->current()->getPathname();
33+
$current = $this->normalizeDirectorySeparator($current);
34+
35+
if ('.' . DIRECTORY_SEPARATOR !== $current[0] . $current[1]) {
36+
$current = '.' . DIRECTORY_SEPARATOR . $current;
37+
}
38+
39+
return !in_array($current, $this->excluded);
40+
}
41+
42+
/**
43+
* (PHP 5 &gt;= 5.1.0)<br/>
44+
* Check whether the inner iterator's current element has children
45+
*
46+
* @link http://php.net/manual/en/recursivefilteriterator.haschildren.php
47+
* @return bool true if the inner iterator has children, otherwise false
48+
*/
49+
public function hasChildren()
50+
{
51+
return $this->iterator->hasChildren();
52+
}
53+
54+
/**
55+
* (PHP 5 &gt;= 5.1.0)<br/>
56+
* Return the inner iterator's children contained in a RecursiveFilterIterator
57+
*
58+
* @link http://php.net/manual/en/recursivefilteriterator.getchildren.php
59+
* @return \RecursiveFilterIterator containing the inner iterator's children.
60+
*/
61+
public function getChildren()
62+
{
63+
return new self($this->iterator->getChildren(), $this->excluded);
64+
}
65+
66+
/**
67+
* @param string $file
68+
* @return string
69+
*/
70+
private function getPathname($file)
71+
{
72+
$file = $this->normalizeDirectorySeparator($file);
73+
74+
if ('.' . DIRECTORY_SEPARATOR !== $file[0] . $file[1]) {
75+
$file = '.' . DIRECTORY_SEPARATOR . $file;
76+
}
77+
78+
$directoryFile = new \SplFileInfo($file);
79+
return $directoryFile->getPathname();
80+
}
81+
82+
/**
83+
* @param string $file
84+
* @return string
85+
*/
86+
private function normalizeDirectorySeparator($file)
87+
{
88+
return str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $file);
89+
}
90+
}

0 commit comments

Comments
 (0)