11
11
12
12
class Processor
13
13
{
14
- const TYPE_SCSS = 'scss ' ;
15
- const TYPE_COMPASS = 'scss ' ;
16
- const TYPE_SASS = 'sass ' ;
17
- const TYPE_LESS = 'less ' ;
14
+ const FORMATTER_COMPRESSED = 'compressed ' ;
15
+ const FORMATTER_CRUNCHED = 'crunched ' ;
16
+ const FORMATTER_EXPANDED = 'expanded ' ;
17
+ const FORMATTER_NESTED = 'nested ' ;
18
+ const FORMATTER_COMPACT = 'compact ' ;
19
+ const SUPPORTED_FORMATTERS = [
20
+ self ::FORMATTER_COMPRESSED ,
21
+ self ::FORMATTER_CRUNCHED ,
22
+ self ::FORMATTER_EXPANDED ,
23
+ self ::FORMATTER_NESTED ,
24
+ self ::FORMATTER_COMPACT
25
+ ];
18
26
/**
19
27
* @var IOInterface
20
28
*/
@@ -119,30 +127,18 @@ public function saveOutput()
119
127
*/
120
128
public function processFiles ($ formatter )
121
129
{
122
- switch ($ formatter ) {
123
- case 'compressed ' :
124
- case 'crunched ' :
125
- case 'expanded ' :
126
- case 'nested ' :
127
- case 'compact ' :
128
- $ formatter = 'Leafo \\ScssPhp \\Formatter \\' . ucfirst ($ formatter );
129
- break ;
130
- default :
131
- throw new \InvalidArgumentException ('available options are: xxx ' );
132
- }
133
-
134
130
foreach ($ this ->files as $ file ) {
135
131
$ this ->io ->write ("<info>processing</info>: {$ file ->getSourcePath ()}" );
136
132
$ file ->setSourceContentFromSourcePath ();
137
133
138
134
switch ($ file ->getType ()) {
139
- case static ::TYPE_COMPASS :
140
- case static ::TYPE_SCSS :
141
- case static ::TYPE_SASS :
142
- $ this ->sass ->setFormatter ($ formatter );
135
+ case File ::TYPE_COMPASS :
136
+ case File ::TYPE_SCSS :
137
+ case File ::TYPE_SASS :
138
+ $ this ->sass ->setFormatter ($ this -> getFormatterClass ( $ formatter) );
143
139
$ content = $ this ->sass ->compile ($ file ->getSourceContent ());
144
140
break ;
145
- case static ::TYPE_LESS :
141
+ case File ::TYPE_LESS :
146
142
$ content = $ this ->less ->compile ($ file ->getSourceContent ());
147
143
break ;
148
144
default :
@@ -152,4 +148,18 @@ public function processFiles($formatter)
152
148
$ file ->setParsedContent ($ content );
153
149
}
154
150
}
151
+
152
+ /**
153
+ * @param string $formatter
154
+ *
155
+ * @return string
156
+ */
157
+ protected function getFormatterClass ($ formatter )
158
+ {
159
+ if (!in_array ($ formatter , static ::SUPPORTED_FORMATTERS )) {
160
+ throw new \InvalidArgumentException ('unknown formatter, available options are: ' . print_r (static ::SUPPORTED_FORMATTERS , true ));
161
+ }
162
+
163
+ return 'Leafo \\ScssPhp \\Formatter \\' . ucfirst ($ formatter );
164
+ }
155
165
}
0 commit comments