CreationTimeFilterIterator::accept()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\FileOperations\Filters;
6
7
/**
8
 * Filters a RecursiveDirectoryIterator based on how many seconds ago it was modified
9
 */
10 View Code Duplication
class CreationTimeFilterIterator extends \FilterIterator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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();
0 ignored issues
show
Bug introduced by
The method getRealPath() does not seem to exist on object<unreal4u\FileOper...tionTimeFilterIterator>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
        // Broken symlinks will have an empty RealPath (because they don't exist)
40
        if (!empty($filename)) {
41
            return ($this->getMTime() <= $this->fromTimestamp);
0 ignored issues
show
Bug introduced by
The method getMTime() does not seem to exist on object<unreal4u\FileOper...tionTimeFilterIterator>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
        }
43
44
        // Empty filename, so most probably a broken symlink
45
        return false;
46
    }
47
}
48