Code Duplication    Length = 38-38 lines in 2 locations

src/Filters/CreationTimeFilterIterator.php 1 location

@@ 10-47 (lines=38) @@
7
/**
8
 * Filters a RecursiveDirectoryIterator based on how many seconds ago it was modified
9
 */
10
class CreationTimeFilterIterator extends \FilterIterator
11
{
12
    /**
13
     * From which timestamp we must consider a file to be valid to be considered
14
     *
15
     * @var int
16
     */
17
    protected $fromTimestamp = 0;
18
19
    /**
20
     * Constructor
21
     *
22
     * @param \Iterator $iterator
23
     * @param int $secondsAgo
24
     */
25
    public function __construct(\Iterator $iterator, $secondsAgo)
26
    {
27
        parent::__construct($iterator);
28
        $this->fromTimestamp = time() - $secondsAgo;
29
    }
30
31
    /**
32
     * All files that comply with this rule will be considered
33
     *
34
     * @see FilterIterator::accept()
35
     */
36
    public function accept(): bool
37
    {
38
        $filename = $this->getRealPath();
39
        // Broken symlinks will have an empty RealPath (because they don't exist)
40
        if (!empty($filename)) {
41
            return ($this->getMTime() <= $this->fromTimestamp);
42
        }
43
44
        // Empty filename, so most probably a broken symlink
45
        return false;
46
    }
47
}
48

src/Filters/SymlinksFilterIterator.php 1 location

@@ 10-47 (lines=38) @@
7
/**
8
 * Filters a RecursiveDirectoryIterator based on how many seconds ago it was modified
9
 */
10
class SymlinksFilterIterator extends \FilterIterator
11
{
12
    /**
13
     * Whether to include broken symlinks
14
     *
15
     * @var bool
16
     */
17
    private $includeBrokenSymlink;
18
19
    /**
20
     * Constructor
21
     *
22
     * @param \Iterator $iterator
23
     * @param bool $includeBrokenSymlink
24
     */
25
    public function __construct(\Iterator $iterator, bool $includeBrokenSymlink = true)
26
    {
27
        parent::__construct($iterator);
28
        $this->includeBrokenSymlink = $includeBrokenSymlink;
29
    }
30
31
    /**
32
     * All files that comply with this rule will be considered
33
     *
34
     * @see FilterIterator::accept()
35
     */
36
    public function accept(): bool
37
    {
38
        $filename = $this->getRealPath();
39
        // Broken symlinks will have an empty RealPath (because they don't exist)
40
        if (!empty($filename)) {
41
            return true;
42
        }
43
44
        // Empty filename, so most probably a broken symlink
45
        return $this->includeBrokenSymlink;
46
    }
47
}
48