DirectoryLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 8 2
A getFilesIterator() 0 6 1
1
<?php
2
3
namespace Amock\Loader;
4
5
use RecursiveDirectoryIterator;
6
use RecursiveIteratorIterator;
7
use RegexIterator;
8
use RecursiveRegexIterator;
9
use Iterator;
10
11
class DirectoryLoader implements Loader
12
{
13
    private $directory;
14
15 9
    public function __construct(string $directory)
16
    {
17 9
        $this->directory = $directory;
18 9
    }
19
20 8
    public function get(): string
21
    {
22 8
        $content = '';
23 8
        foreach($this->getFilesIterator() as $file) {
24 8
            $content .= file_get_contents(reset($file)) . PHP_EOL;
25
        }
26
27 8
        return $content;
28
    }
29
30 8
    private function getFilesIterator(): Iterator
31
    {
32 8
        $directoryIterator = new RecursiveDirectoryIterator($this->directory);
33 8
        $Iterator = new RecursiveIteratorIterator($directoryIterator);
34
35 8
        return new RegexIterator($Iterator, '/^.+\.[A-Z]+$/i', RecursiveRegexIterator::GET_MATCH);
36
    }
37
}
38