Completed
Push — master ( e5b3ec...079626 )
by Níckolas Daniel
05:34
created

JigsawBuiltOutputFilesRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace PODEntender\Infrastructure\Domain\Model\FileProcessing;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Support\Collection;
7
use PODEntender\Domain\Model\FileProcessing\OutputFile;
8
use PODEntender\Domain\Model\FileProcessing\OutputFileCollection;
9
use PODEntender\Domain\Model\FileProcessing\OutputFileRepository;
10
use TightenCo\Jigsaw\Jigsaw;
11
12
class JigsawBuiltOutputFilesRepository implements OutputFileRepository
13
{
14
    private $jigsaw;
15
16
    private $filesystem;
17
18 2
    public function __construct(Jigsaw $jigsaw, Filesystem $filesystem)
19
    {
20 2
        $this->jigsaw = $jigsaw;
21 2
        $this->filesystem = $filesystem;
22 2
    }
23
24 2
    public function all(): OutputFileCollection
25
    {
26
        /** @var Collection|array $paths */
27 2
        $paths = $this->jigsaw->getOutputPaths();
28
29
        $paths = array_map(function (string $path) {
30 2
            return $this->jigsaw->getDestinationPath() . $path . '/index.html';
31 2
        }, is_array($paths) ? $paths : $paths->toArray());
0 ignored issues
show
introduced by
The condition is_array($paths) is always true.
Loading history...
32
33
        $paths = array_filter($paths, function (string $path) {
34 2
            return $this->filesystem->exists($path);
35 2
        });
36
37
        return new OutputFileCollection(array_map(function (string $path) {
38 2
            return new OutputFile($path, $this->filesystem->get($path));
39 2
        }, $paths));
40
    }
41
}
42