TemplateOutput::getOutputPath()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

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