Completed
Branch 4.0 (c710b5)
by Serhii
02:04
created

FileStorage   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 4 1
B getFileNames() 0 20 8
1
<?php
2
3
4
namespace EndorphinStudio\Detector\Storage;
5
6
use \Ds\Set;
7
8
class FileStorage  extends AbstractStorage implements StorageInterface
0 ignored issues
show
Coding Style introduced by
Expected 1 space after class name; 2 found
Loading history...
Coding Style introduced by
Expected 1 space before extends keyword; 2 found
Loading history...
9
{
10
    /**
11
     * Base method
12
     * @return array nothing
13
     */
14
    public function getConfig(): array
15
    {
16
        return [];
17
    }
18
19
    protected function getFileNames(string $directory = 'default'): array
20
    {
21
        if($directory === 'default') {
22
            $directoryIterator = new \DirectoryIterator($this->dataDirectory);
23
        } else {
24
            $directoryIterator = new \DirectoryIterator($directory);
25
        }
26
        $files = new Set();
27
        foreach ($directoryIterator as $file) {
28
            if($file->isDir() && !$file->isDot()) {
29
                $dirFiles = $this->getFileNames($file->getRealPath());
30
                $files->add($dirFiles);
31
            }
32
33
            if($file->isFile() && !$file->isLink() && $file->isReadable()) {
34
                $files->add($file->getRealPath());
35
            }
36
        }
37
        return $files->toArray();
38
    }
39
}