Passed
Push — master ( 90a0e3...c7d56e )
by Sébastien
02:03
created

DirectoryScanner::findFiles()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 4
nop 2
dl 0
loc 21
ccs 12
cts 12
cp 1
crap 4
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Cli\FileSystem;
6
7
use Symfony\Component\Finder\Finder;
8
9
class DirectoryScanner
10
{
11
    /**
12
     * @return array<\SplFileInfo>
13
     */
14 3
    public function findFiles(string $path, ?array $validExtensions = null): array
15
    {
16 3
        $files = (new Finder())->files()
17 3
            ->in($path)
18 3
            ->ignoreUnreadableDirs();
19
20 3
        if ($validExtensions !== null && count($validExtensions) > 0) {
21 3
            $files->name(sprintf(
22 3
                '/\.(%s)$/',
23 3
                implode('|', $validExtensions)
24
            ));
25
        }
26
27 3
        $videos = [];
28
29
        /** @var \SplFileInfo $file */
30 3
        foreach ($files as $file) {
31 3
            $videos[] = $file;
32
        }
33
34 3
        return $videos;
35
    }
36
}
37