Completed
Push — master ( 9b25f2...d42705 )
by Tomáš
09:42 queued 07:08
created

File::changeContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Renderable\File;
11
12
use SplFileInfo;
13
14
class File
15
{
16
    /**
17
     * @var SplFileInfo
18
     */
19
    protected $fileInfo;
20
21
    /**
22
     * @var string
23
     */
24
    private $relativeSource;
25
26
    /**
27
     * @var string
28
     */
29
    private $outputPath;
30
31
    /**
32
     * @var string
33
     */
34
    private $content;
35
36
    /**
37
     * @var array
38
     */
39
    private $configuration = [];
40
41 3
    public function __construct(SplFileInfo $fileInfo, string $relativeSource)
42
    {
43 3
        $this->relativeSource = $relativeSource;
44 3
        $this->fileInfo = $fileInfo;
45 3
        $this->content = file_get_contents($fileInfo->getRealPath());
46 3
    }
47
48 1
    public function setOutputPath(string $outputPath)
49
    {
50 1
        $this->outputPath = $outputPath;
51 1
    }
52
53
    public function getRelativeSource() : string
54
    {
55
        return $this->relativeSource;
56
    }
57
58 2
    public function getBaseName() : string
59
    {
60 2
        return $this->fileInfo->getBasename('.'.$this->fileInfo->getExtension());
61
    }
62
63
    public function getPrimaryExtension() : string
64
    {
65
        $fileParts = explode('.', $this->fileInfo->getBasename());
66
        if (count($fileParts) > 2) {
67
            return $fileParts[count($fileParts) - 2];
68
        }
69
70
        return $fileParts[count($fileParts) - 1];
71
    }
72
73
    public function getExtension() : string
74
    {
75
        return $this->fileInfo->getExtension();
76
    }
77
78
    public function getRelativeUrl() : string
79
    {
80
        return rtrim($this->outputPath, '/index.html');
81
    }
82
83 3
    public function getContent() : string
84
    {
85 3
        return $this->content;
86
    }
87
88 2
    public function changeContent(string $newContent)
89
    {
90 2
        $this->content = $newContent;
91 2
    }
92
93 1
    public function setConfiguration(array $configuration)
94
    {
95 1
        $this->configuration = $configuration;
96 1
    }
97
98 2
    public function getConfiguration() : array
99
    {
100 2
        return $this->configuration;
101
    }
102
103 1
    public function getOutputPath() : string
104
    {
105 1
        return $this->outputPath;
106
    }
107
108
    public function getLayout() : string
109
    {
110
        return $this->configuration['layout'] ?? 'default';
111
    }
112
}
113