6
6
7
7
class File
8
8
{
9
- const TYPE_SCSS = 'scss ' ;
10
- const TYPE_SASS = 'sass ' ;
11
- const TYPE_COMPASS = 'compass ' ;
12
- const TYPE_LESS = 'less ' ;
13
- const TYPE_UNKNOWN = 'unknown ' ;
14
- /**
15
- * @var string[]
16
- */
17
- private static $ extensions = [
18
- self ::TYPE_SCSS ,
19
- self ::TYPE_SASS ,
9
+ const TYPE_UNKNOWN = 'unknown ' ;
10
+ const TYPE_COMPASS = 'compass ' ;
11
+ const TYPE_SASS = 'sass ' ;
12
+ const TYPE_SCSS = 'scss ' ;
13
+ const TYPE_LESS = 'less ' ;
14
+ const SUPPORTED_TYPES = [
20
15
self ::TYPE_COMPASS ,
21
- self ::TYPE_LESS ,
16
+ self ::TYPE_SASS ,
17
+ self ::TYPE_SCSS ,
18
+ self ::TYPE_LESS
22
19
];
23
20
/**
24
21
* @var string
@@ -64,15 +61,15 @@ public function getSourcePath()
64
61
public function setSourcePath ($ path )
65
62
{
66
63
$ this ->sourcePath = $ path ;
67
- $ this ->detectSourceTypeFromPath ($ path );
64
+ $ this ->type = $ this -> detectSourceTypeFromPath ($ path );
68
65
69
66
return $ this ;
70
67
}
71
68
72
69
/**
73
70
* @return string
74
71
*/
75
- public function getOutputPath ()
72
+ public function getOutputPath ()
76
73
{
77
74
return $ this ->outputPath ;
78
75
}
@@ -113,7 +110,7 @@ public function setSourceContent($content)
113
110
* @return File
114
111
* @throws FileException
115
112
*/
116
- public function setSourceContentFromSourcePath ()
113
+ public function setSourceContentFromSourcePath ()
117
114
{
118
115
$ this ->sourceContent = $ this ->readSourceContentByPath ();
119
116
@@ -133,7 +130,7 @@ public function getParsedContent()
133
130
*
134
131
* @return File
135
132
*/
136
- public function setParsedContent ($ content )
133
+ public function setParsedContent ($ content )
137
134
{
138
135
$ this ->parsedContent = $ content ;
139
136
@@ -143,7 +140,7 @@ public function setParsedContent($content)
143
140
/**
144
141
* @return string
145
142
*/
146
- public function getType ()
143
+ public function getType ()
147
144
{
148
145
return $ this ->type ;
149
146
}
@@ -162,24 +159,23 @@ public function setType($type)
162
159
163
160
/**
164
161
* @param string $path
165
- *
166
- * @return void
162
+ *
163
+ * @return string
167
164
*/
168
- private function detectSourceTypeFromPath ($ path )
165
+ protected function detectSourceTypeFromPath ($ path )
169
166
{
170
167
$ extension = strtolower (pathinfo ($ path , PATHINFO_EXTENSION ));
171
- if (in_array ($ extension , static ::$ extensions )) {
172
- $ this ->type = $ extension ;
173
- } else {
174
- $ this ->type = static ::TYPE_UNKNOWN ;
175
- }
168
+
169
+ return in_array ($ extension , static ::SUPPORTED_TYPES )
170
+ ? $ extension
171
+ : static ::TYPE_UNKNOWN ;
176
172
}
177
173
178
174
/**
179
175
* @return string
180
176
* @throws FileException
181
177
*/
182
- private function readSourceContentByPath ()
178
+ protected function readSourceContentByPath ()
183
179
{
184
180
if (!file_exists ($ this ->getSourcePath ())) {
185
181
throw new FileException ("file: {$ this ->sourcePath } doesn't exists " );
0 commit comments