FileSystem::getFilesFromPath()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.5126
cc 6
eloc 11
nc 5
nop 1
1
<?php
2
3
namespace NilPortugues\TodoFinder\Finder;
4
5
use InvalidArgumentException;
6
use RecursiveDirectoryIterator;
7
use RecursiveIteratorIterator;
8
9
class FileSystem implements \NilPortugues\TodoFinder\Finder\Interfaces\FileSystem
10
{
11
    /**
12
     * @inheritDoc
13
     */
14
    public function getFilesFromPath($path)
15
    {
16
        if (\false === \is_dir($path) && \false === \is_file($path)) {
17
            throw new InvalidArgumentException("Provided input is not a file nor a valid directory");
18
        }
19
20
        $files = [];
21
22
        $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
23
24
        /** @var \SplFileInfo $filename */
25
        foreach ($iterator as $filename) {
26
            // filter out "." and ".."
27
            if ($filename->isDir()) {
28
                continue;
29
            }
30
31
            if ("php" === \strtolower($filename->getExtension())) {
32
                $files[] = $filename->getRealPath();
33
            }
34
        }
35
36
        return $files;
37
    }
38
}
39