Completed
Push — master ( c0b2e0...0bd897 )
by Eugene
32s
created

FileContainer::getInputPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace EM\CssCompiler\Container;
4
5
/**
6
 * @see   FileContainerTest
7
 *
8
 * @since 0.1
9
 */
10
class FileContainer
11
{
12
    const TYPE_UNKNOWN = 'unknown';
13
    const TYPE_SCSS    = 'scss';
14
    const TYPE_LESS    = 'less';
15
    static $supportedTypes = [
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $supportedTypes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
16
        self::TYPE_SCSS,
17
        self::TYPE_LESS
18
    ];
19
    /**
20
     * @var string
21
     */
22
    private $inputPath;
23
    /**
24
     * @var string
25
     */
26
    private $outputPath;
27
    /**
28
     * @var string
29
     */
30
    private $inputContent;
31
    /**
32
     * @var string
33
     */
34
    private $outputContent;
35
    /**
36
     * @var string
37
     */
38
    private $type;
39
40
    /**
41
     * @param string $inputPath
42
     * @param string $outputPath
43
     */
44
    public function __construct($inputPath, $outputPath)
45
    {
46
        $this
47
            ->setInputPath($inputPath)
48
            ->setOutputPath($outputPath);
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getOutputPath()
55
    {
56
        return $this->outputPath;
57
    }
58
59
    /**
60
     * @param string $path
61
     *
62
     * @return $this
63
     */
64
    public function setOutputPath($path)
65
    {
66
        $this->outputPath = $path;
67
68
        return $this;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getInputContent()
75
    {
76
        return $this->inputContent;
77
    }
78
79
    /**
80
     * @param string $content
81
     *
82
     * @return $this
83
     */
84
    public function setInputContent($content)
85
    {
86
        $this->inputContent = $content;
87
88
        return $this;
89
    }
90
91
    public function getInputPath()
92
    {
93
        return $this->inputPath;
94
    }
95
96
    /**
97
     * @param string $path
98
     *
99
     * @return $this
100
     */
101
    public function setInputPath($path)
102
    {
103
        $this->inputPath = $path;
104
        $this->detectInputTypeByInputPath();
105
106
        return $this;
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public function getOutputContent()
113
    {
114
        return $this->outputContent;
115
    }
116
117
    /**
118
     * @param string $content
119
     *
120
     * @return $this
121
     */
122
    public function setOutputContent($content)
123
    {
124
        $this->outputContent = $content;
125
126
        return $this;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getType()
133
    {
134
        return $this->type;
135
    }
136
137
    /**
138
     * @param string $type
139
     *
140
     * @return $this
141
     */
142
    public function setType($type)
143
    {
144
        $this->type = $type;
145
146
        return $this;
147
    }
148
149
    protected function detectInputTypeByInputPath()
150
    {
151
        $extension = strtolower(pathinfo($this->getInputPath(), PATHINFO_EXTENSION));
152
153
        $type = in_array($extension, static::$supportedTypes)
0 ignored issues
show
Bug introduced by
Since $supportedTypes is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $supportedTypes to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
154
            ? $extension
155
            : static::TYPE_UNKNOWN;
156
157
        $this->setType($type);
158
159
        return $this;
160
    }
161
}
162