AbstractDirectoryRule::appliesTheRule()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
/**
3
 * ShouldPHP
4
 *
5
 * @author  Gabriel Jacinto <[email protected]>
6
 * @status  dev
7
 * @link    https://github.com/GabrielJMJ/ShouldPHP
8
 * @license MIT
9
 */
10
 
11
namespace Gabrieljmj\Should\Runner\Rule\Directory;
12
13
use Gabrieljmj\Should\Runner\Rule\Directory\DirectoryRuleInterface;
14
15
abstract class AbstractDirectoryRule implements DirectoryRuleInterface
16
{
17
    use \Gabrieljmj\Should\Tool\DirectoryValidatorTrait;
18
19
    /**
20
     * Executes the rule, filtering the directory files
21
     *
22
     * @param string $param
23
     * @return array
24
     */
25
    public function execute($param)
26
    {
27
        $dir = $this->validateDir($param);
28
        $path = realpath($dir);
29
30
        $entries = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
31
        $files = [];
32
33 View Code Duplication
        foreach ($entries as $key => $name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
34
            $files[$key] = $name;
35
            $e = explode('\\', $name);
36
            if (end($e) === '.' || end($e) === '..' || is_dir($name) || !$this->appliesTheRule($name)) {
37
                unset($files[$key]);
38
            }
39
        }
40
41
        return $files;
42
    }
43
44
    /**
45
     * Applies the rule
46
     *
47
     * @param string $file
48
     * @return boolean
49
     */
50
    abstract protected function appliesTheRule($file);
51
}