RenderableFilesProcessor   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 140
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 7
dl 0
loc 140
ccs 45
cts 45
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A createFileObjectsFromFileInfos() 0 9 2
A setRoutesToFiles() 0 6 2
A setFileConfigurationToFile() 0 6 2
A formatFileContentFromMarkdownToHtml() 0 6 2
A formatFileContentFromLatteToHtml() 0 6 2
A processFiles() 0 17 2
A setPostsToConfiguration() 0 6 2
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\Renderable;
11
12
use SplFileInfo;
13
use Symplify\PHP7_Sculpin\Configuration\Configuration;
14
use Symplify\PHP7_Sculpin\Output\FileSystemWriter;
15
use Symplify\PHP7_Sculpin\Renderable\Configuration\ConfigurationDecorator;
16
use Symplify\PHP7_Sculpin\Renderable\File\File;
17
use Symplify\PHP7_Sculpin\Renderable\File\FileFactory;
18
use Symplify\PHP7_Sculpin\Renderable\File\PostFile;
19
use Symplify\PHP7_Sculpin\Renderable\Latte\LatteDecorator;
20
use Symplify\PHP7_Sculpin\Renderable\Markdown\MarkdownDecorator;
21
use Symplify\PHP7_Sculpin\Renderable\Routing\RouteDecorator;
22
23
final class RenderableFilesProcessor
24
{
25
    /**
26
     * @var FileFactory
27
     */
28
    private $fileFactory;
29
30
    /**
31
     * @var RouteDecorator
32
     */
33
    private $routeDecorator;
34
35
    /**
36
     * @var ConfigurationDecorator
37
     */
38
    private $configurationDecorator;
39
40
    /**
41
     * @var MarkdownDecorator
42
     */
43
    private $markdownDecorator;
44
    /**
45
     * @var LatteDecorator
46
     */
47
    private $latteDecorator;
48
49
    /**
50
     * @var FileSystemWriter
51
     */
52
    private $fileSystemWriter;
53
54
    /**
55
     * @var Configuration
56
     */
57
    private $configuration;
58
59 6
    public function __construct(
60
        FileFactory $fileFactory,
61
        RouteDecorator $routeDecorator,
62
        ConfigurationDecorator $configurationDecorator,
63
        MarkdownDecorator $markdownDecorator,
64
        LatteDecorator $latteDecorator,
65
        FileSystemWriter $fileSystemWriter,
66
        Configuration $configuration
67
    ) {
68 6
        $this->fileFactory = $fileFactory;
69 6
        $this->routeDecorator = $routeDecorator;
70 6
        $this->configurationDecorator = $configurationDecorator;
71 6
        $this->markdownDecorator = $markdownDecorator;
72 6
        $this->latteDecorator = $latteDecorator;
73 6
        $this->fileSystemWriter = $fileSystemWriter;
74 6
        $this->configuration = $configuration;
75 6
    }
76
77
    /**
78
     * @param SplFileInfo[] $fileInfos
79
     */
80 3
    public function processFiles(array $fileInfos)
81
    {
82 3
        if (! count($fileInfos)) {
83 1
            return;
84
        }
85
86 3
        $files = $this->createFileObjectsFromFileInfos($fileInfos);
87
88 3
        $this->setPostsToConfiguration($files);
89 3
        $this->setRoutesToFiles($files);
90
91 3
        $this->setFileConfigurationToFile($files);
92 3
        $this->formatFileContentFromMarkdownToHtml($files);
93 3
        $this->formatFileContentFromLatteToHtml($files);
94
95 3
        $this->fileSystemWriter->copyRenderableFiles($files);
96 3
    }
97
98
    /**
99
     * @param array $fileInfos
100
     *
101
     * @return array
102
     */
103 3
    private function createFileObjectsFromFileInfos(array $fileInfos):array
104
    {
105 3
        $files = [];
106 3
        foreach ($fileInfos as $id => $fileInfo) {
107 3
            $files[$id] = $this->fileFactory->create($fileInfo);
108
        }
109
110 3
        return $files;
111
    }
112
113
    /**
114
     * @param File[] $files
115
     */
116 3
    private function setPostsToConfiguration(array $files)
117
    {
118 3
        if (reset($files) instanceof PostFile) {
119 2
            $this->configuration->addGlobalVarialbe('posts', $files);
120
        }
121 3
    }
122
123
    /**
124
     * @param File[] $files
125
     */
126 3
    private function setRoutesToFiles(array $files)
127
    {
128 3
        foreach ($files as $file) {
129 3
            $this->routeDecorator->decorateFile($file);
130
        }
131 3
    }
132
133
    /**
134
     * @param File[] $files
135
     */
136 3
    private function setFileConfigurationToFile(array $files)
137
    {
138 3
        foreach ($files as $file) {
139 3
            $this->configurationDecorator->decorateFile($file);
140
        }
141 3
    }
142
143
    /**
144
     * @param File[] $files
145
     */
146 3
    private function formatFileContentFromMarkdownToHtml(array $files)
147
    {
148 3
        foreach ($files as $file) {
149 3
            $this->markdownDecorator->decorateFile($file);
150
        }
151 3
    }
152
153
    /**
154
     * @param File[] $files
155
     */
156 3
    private function formatFileContentFromLatteToHtml(array $files)
157
    {
158 3
        foreach ($files as $file) {
159 3
            $this->latteDecorator->decorateFile($file);
160
        }
161 3
    }
162
}
163