Completed
Push — master ( 7b9d9c...6bacbf )
by Neomerx
08:04
created

TemplateOutput   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 0
dl 0
loc 189
ccs 49
cts 49
cp 1
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getOutputRootFolder() 0 4 1
A setOutputRootFolder() 0 10 1
A getOutputSubFolder() 0 4 1
A setOutputSubFolder() 0 8 1
A getOutputFileName() 0 4 1
A setOutputFileName() 0 10 1
A getOutputContent() 0 4 1
A setOutputContent() 0 6 1
A getOutputFolder() 0 17 4
A getOutputPath() 0 13 3
A reset() 0 5 1
1
<?php namespace Limoncello\Application\Commands;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
/**
20
 * @package Limoncello\Application
21
 */
22
class TemplateOutput
23
{
24
    /**
25
     * @var string
26
     */
27
    private $outputRootFolder;
28
29
    /**
30
     * @var string
31
     */
32
    private $outputSubFolder;
33
34
    /**
35
     * @var string
36
     */
37
    private $outputFileName;
38
39
    /**
40
     * @var string
41
     */
42
    private $outputContent;
43
44
    /**
45
     * @var string|null
46
     */
47
    private $outputFolder = null;
48
49
    /**
50
     * @var string|null
51
     */
52
    private $outputPath = null;
53
54
    /**
55
     * @param string $outputRootFolder
56
     * @param string $outputFileName
57
     * @param string $outputContent
58
     * @param string $outputSubFolder
59
     */
60 7
    public function __construct(
61
        string $outputRootFolder,
62
        string $outputFileName,
63
        string $outputContent,
64
        string $outputSubFolder = ''
65
    ) {
66
        $this
67 7
            ->setOutputRootFolder($outputRootFolder)
68 7
            ->setOutputSubFolder($outputSubFolder)
69 7
            ->setOutputFileName($outputFileName)
70 7
            ->setOutputContent($outputContent);
71
    }
72
73
74
    /**
75
     * @return string
76
     */
77 7
    public function getOutputRootFolder(): string
78
    {
79 7
        return $this->outputRootFolder;
80
    }
81
82
    /**
83
     * @param string $outputRootFolder
84
     *
85
     * @return self
86
     */
87 7
    public function setOutputRootFolder(string $outputRootFolder): self
88
    {
89 7
        assert(empty($outputRootFolder) === false);
90
91 7
        $this->outputRootFolder = $outputRootFolder;
92
93 7
        $this->reset();
94
95 7
        return $this;
96
    }
97
98
    /**
99
     * @return string
100
     */
101 7
    public function getOutputSubFolder(): string
102
    {
103 7
        return $this->outputSubFolder;
104
    }
105
106
    /**
107
     * @param string $outputSubFolder
108
     *
109
     * @return self
110
     */
111 7
    public function setOutputSubFolder(string $outputSubFolder): self
112
    {
113 7
        $this->outputSubFolder = $outputSubFolder;
114
115 7
        $this->reset();
116
117 7
        return $this;
118
    }
119
120
    /**
121
     * @return string
122
     */
123 7
    public function getOutputFileName(): string
124
    {
125 7
        return $this->outputFileName;
126
    }
127
128
    /**
129
     * @param string $outputFileName
130
     *
131
     * @return self
132
     */
133 7
    public function setOutputFileName(string $outputFileName): self
134
    {
135 7
        assert(empty($outputFileName) === false);
136
137 7
        $this->outputFileName = $outputFileName;
138
139 7
        $this->reset();
140
141 7
        return $this;
142
    }
143
144
    /**
145
     * @return string
146
     */
147 4
    public function getOutputContent(): string
148
    {
149 4
        return $this->outputContent;
150
    }
151
152
    /**
153
     * @param string $outputContent
154
     *
155
     * @return self
156
     */
157 7
    public function setOutputContent(string $outputContent): self
158
    {
159 7
        $this->outputContent = $outputContent;
160
161 7
        return $this;
162
    }
163
164
    /**
165
     * @return string
166
     */
167 7
    public function getOutputFolder(): string
168
    {
169 7
        if ($this->outputFolder === null) {
170 7
            $folder = $this->getOutputRootFolder();
171
172 7
            if (empty($this->getOutputSubFolder()) === false) {
173 3
                if ($folder[-1] !== DIRECTORY_SEPARATOR) {
174 3
                    $folder .= DIRECTORY_SEPARATOR;
175
                }
176 3
                $folder .= $this->getOutputSubFolder();
177
            }
178
179 7
            $this->outputFolder = $folder;
180
        }
181
182 7
        return $this->outputFolder;
183
    }
184
185
    /**
186
     * @return string
187
     */
188 7
    public function getOutputPath(): string
189
    {
190 7
        if ($this->outputPath === null) {
191 7
            $folder = $this->getOutputFolder();
192 7
            if ($folder[-1] !== DIRECTORY_SEPARATOR) {
193 7
                $folder .= DIRECTORY_SEPARATOR;
194
            }
195
196 7
            $this->outputPath = $folder . $this->getOutputFileName();
197
        }
198
199 7
        return $this->outputPath;
200
    }
201
202
    /**
203
     * @return void
204
     */
205 7
    private function reset(): void
206
    {
207 7
        $this->outputFolder = null;
208 7
        $this->outputPath   = null;
209
    }
210
}
211