SourceFileStorage::getPostFiles()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Source;
11
12
use Nette\Utils\Finder;
13
use SplFileInfo;
14
use Symplify\PHP7_Sculpin\Contract\Source\SourceFileFilter\SourceFileFilterInterface;
15
16
final class SourceFileStorage
17
{
18
    /**
19
     * @var SplFileInfo[][]
20
     */
21
    private $sourceFilesByType = [];
22
23
    /**
24
     * @var SourceFileFilterInterface[]
25
     */
26
    private $sourceFileFilters = [];
27
28 5
    public function addSourceFileFilter(SourceFileFilterInterface $sourceFileFilter)
29
    {
30 5
        $this->sourceFileFilters[$sourceFileFilter->getName()] = $sourceFileFilter;
31 5
        $this->sourceFilesByType[$sourceFileFilter->getName()] = [];
32 5
    }
33
34 2
    public function loadSourcesFromFinder(Finder $finder)
35
    {
36 2
        foreach ($finder as $fileInfo) {
37 2
            $this->addSource($fileInfo);
38
        }
39 2
    }
40
41 2
    private function addSource(SplFileInfo $fileInfo)
42
    {
43 2
        foreach ($this->sourceFileFilters as $sourceFileFilter) {
44 2
            if ($sourceFileFilter->matchesFileSource($fileInfo)) {
45 2
                $this->sourceFilesByType[$sourceFileFilter->getName()][] = $fileInfo;
46
            }
47
        }
48 2
    }
49
50
    /**
51
     * @return SplFileInfo[]
52
     */
53 2
    public function getStaticFiles() : array
54
    {
55 2
        return $this->sourceFilesByType[SourceFileTypes::STATIC];
56
    }
57
58
    /**
59
     * @return SplFileInfo[]
60
     */
61 2
    public function getRenderableFiles() : array
62
    {
63 2
        return $this->sourceFilesByType[SourceFileTypes::RENDERABLE];
64
    }
65
66
    /**
67
     * @return SplFileInfo[]
68
     */
69 2
    public function getConfigurationFiles() : array
70
    {
71 2
        return $this->sourceFilesByType[SourceFileTypes::CONFIGURATION];
72
    }
73
74
    /**
75
     * @return SplFileInfo[]
76
     */
77 2
    public function getPostFiles() : array
78
    {
79 2
        return $this->sourceFilesByType[SourceFileTypes::POSTS];
80
    }
81
82
    /**
83
     * @return SplFileInfo[]
84
     */
85 2
    public function getLayoutFiles() : array
86
    {
87 2
        return $this->sourceFilesByType[SourceFileTypes::LAYOUTS];
88
    }
89
}
90