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

DirectoryScanner   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A findFiles() 0 21 4
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