FileHelper::getListOfAllPHPFiles()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Todolo\Helper;
6
7
use RecursiveDirectoryIterator;
8
use RecursiveIteratorIterator;
9
10
class FileHelper
11
{
12
    /**
13
     * @return array<string>
14
     */
15 2
    public function getListOfAllPHPFiles(string $dir): array
16
    {
17 2
        $result = [];
18
19 2
        $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
20
21 2
        foreach ($rii as $file) {
22 2
            if ($file->isFile() && str_contains($file->getFilename(), '.php')) {
23 2
                $fullpath = $file->getPath().'/'.$file->getFilename();
24
25
                // remove given dir from fullpath
26 2
                $fullpath = str_replace($dir, '', $fullpath);
27
28 2
                $result[] = $fullpath;
29
            }
30
        }
31
32 2
        return $result;
33
    }
34
}
35