Completed
Pull Request — master (#11)
by Tomáš
02:50
created

AbstractSource   B

Complexity

Total Complexity 36

Size/Duplication

Total Lines 302
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 3

Test Coverage

Coverage 14.47%

Importance

Changes 0
Metric Value
wmc 36
lcom 4
cbo 3
dl 0
loc 302
ccs 11
cts 76
cp 0.1447
rs 8.8
c 0
b 0
f 0

27 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 6 2
A sourceId() 0 4 1
A isRaw() 0 4 1
A content() 0 4 1
A setContent() 0 8 1
A formattedContent() 0 4 1
A setFormattedContent() 0 4 1
A data() 0 4 1
A hasChanged() 0 4 1
A setHasChanged() 0 4 1
A setHasNotChanged() 0 4 1
A permalink() 0 4 1
A setPermalink() 0 4 1
A useFileReference() 0 4 1
A canBeFormatted() 0 4 1
A isGenerator() 0 4 1
A setIsGenerator() 0 4 1
A setIsNotGenerator() 0 4 1
A isGenerated() 0 4 1
A setIsGenerated() 0 4 1
A setIsNotGenerated() 0 4 1
A forceReprocess() 0 4 1
A relativePathname() 0 4 1
A filename() 0 4 1
A file() 0 4 1
A url() 0 4 1
B duplicate() 0 15 9
1
<?php
2
3
/*
4
 * This file is a part of Sculpin.
5
 *
6
 * (c) Dragonfly Development Inc.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Symplify\PHP7_Sculpin\Source;
13
14
use Symplify\PHP7_Sculpin\Permalink\Permalink;
15
use Dflydev\DotAccessConfiguration\Configuration as Data;
16
17
abstract class AbstractSource implements SourceInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $sourceId;
23
24
    /**
25
     * @var bool
26
     */
27
    protected $isRaw;
28
29
    /**
30
     * @var string
31
     */
32
    protected $content;
33
34
    /**
35
     * @var string
36
     */
37
    protected $formattedContent;
38
39
    /**
40
     * @var Data
41
     */
42
    protected $data;
43
44
    /**
45
     * @var bool
46
     */
47
    protected $hasChanged;
48
49
    /**
50
     * @var Permalink
51
     */
52
    protected $permalink;
53
54
    /**
55
     * @var \SplFileInfo
56
     */
57
    protected $file;
58
59
    /**
60
     * @var string
61
     */
62
    protected $relativePathname;
63
64
    /**
65
     * @var string
66
     */
67
    protected $filename;
68
69
    /**
70
     * @var bool
71
     */
72
    protected $useFileReference = false;
73
74
    /**
75
     * @var bool
76
     */
77
    protected $canBeFormatted = false;
78
79
    /**
80
     * @var bool
81
     */
82
    protected $isGenerator = false;
83
84
    /**
85
     * @var bool
86
     */
87
    protected $isGenerated = false;
88
89 6
    protected function init(bool $hasChanged = null)
90
    {
91 6
        if (null !== $hasChanged) {
92
            $this->hasChanged = $hasChanged;
93
        }
94 6
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99 3
    public function sourceId()
100
    {
101 3
        return $this->sourceId;
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function isRaw()
108
    {
109
        return $this->isRaw;
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function content()
116
    {
117
        return $this->content;
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    public function setContent($content = null)
124
    {
125
        $this->content = $content;
126
127
        // If we are setting content, we are going to assume that we should
128
        // not be using file references on output.
129
        $this->useFileReference = false;
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135
    public function formattedContent()
136
    {
137
        return $this->formattedContent;
138
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143
    public function setFormattedContent($formattedContent = null)
144
    {
145
        $this->formattedContent = $formattedContent;
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151 8
    public function data()
152
    {
153 8
        return $this->data;
154
    }
155
156
    /**
157
     * {@inheritdoc}
158
     */
159
    public function hasChanged()
160
    {
161
        return $this->hasChanged;
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167
    public function setHasChanged()
168
    {
169
        $this->hasChanged = true;
170
    }
171
172
    /**
173
     * {@inheritdoc}
174
     */
175
    public function setHasNotChanged()
176
    {
177
        $this->hasChanged = false;
178
    }
179
180
    /**
181
     * {@inheritdoc}
182
     */
183
    public function permalink()
184
    {
185
        return $this->permalink;
186
    }
187
188
    /**
189
     * {@inheritdoc}
190
     */
191
    public function setPermalink(Permalink $permalink)
192
    {
193
        $this->permalink = $permalink;
194
    }
195
196
    /**
197
     * {@inheritdoc}
198
     */
199
    public function useFileReference()
200
    {
201
        return $this->useFileReference;
202
    }
203
204
    /**
205
     * {@inheritdoc}
206
     */
207 4
    public function canBeFormatted()
208
    {
209 4
        return $this->canBeFormatted;
210
    }
211
212
    /**
213
     * {@inheritdoc}
214
     */
215
    public function isGenerator()
216
    {
217
        return $this->isGenerator;
218
    }
219
220
    /**
221
     * {@inheritdoc}
222
     */
223
    public function setIsGenerator()
224
    {
225
        $this->isGenerator = true;
226
    }
227
228
    /**
229
     * {@inheritdoc}
230
     */
231
    public function setIsNotGenerator()
232
    {
233
        $this->isGenerator = false;
234
    }
235
236
    /**
237
     * {@inheritdoc}
238
     */
239
    public function isGenerated()
240
    {
241
        return $this->isGenerated;
242
    }
243
244
    /**
245
     * {@inheritdoc}
246
     */
247
    public function setIsGenerated()
248
    {
249
        $this->isGenerated = true;
250
    }
251
252
    /**
253
     * {@inheritdoc}
254
     */
255
    public function setIsNotGenerated()
256
    {
257
        $this->isGenerated = false;
258
    }
259
260
    /**
261
     * {@inheritdoc}
262
     */
263
    public function forceReprocess()
264
    {
265
        $this->init(true);
266
    }
267
268
    /**
269
     * {@inheritdoc}
270
     */
271 7
    public function relativePathname()
272
    {
273 7
        return $this->relativePathname;
274
    }
275
276
    /**
277
     * {@inheritdoc}
278
     */
279
    public function filename()
280
    {
281
        return $this->filename;
282
    }
283
284
    /**
285
     * {@inheritdoc}
286
     */
287
    public function file()
288
    {
289
        return $this->file;
290
    }
291
292
    /**
293
     * {@inheritdoc}
294
     */
295
    public function url()
296
    {
297
        return $this->permalink()->relativeUrlPath();
298
    }
299
300
    /**
301
     * {@inheritdoc}
302
     */
303
    public function duplicate($newSourceId, array $options = [])
304
    {
305
        return new MemorySource(
306
            $newSourceId,
307
            new Data($this->data->exportRaw()),
308
            isset($options['content']) ? $options['content'] : $this->content,
309
            isset($options['formattedContent']) ? $options['formattedContent'] : $this->formattedContent,
310
            isset($options['relativePathname']) ? $options['relativePathname'] : $this->relativePathname,
311
            isset($options['filename']) ? $options['filename'] : $this->filename,
312
            isset($options['file']) ? $options['file'] : $this->file,
313
            isset($options['isRaw']) ? $options['isRaw'] : $this->isRaw,
314
            isset($options['canBeFormatted']) ? $options['canBeFormatted'] : $this->canBeFormatted,
315
            isset($options['hasChanged']) ? $options['hasChanged'] : $this->hasChanged
316
        );
317
    }
318
}
319