1111
1212class Processor
1313{
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+ ];
1826 /**
1927 * @var IOInterface
2028 */
@@ -119,30 +127,18 @@ public function saveOutput()
119127 */
120128 public function processFiles ($ formatter )
121129 {
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-
134130 foreach ($ this ->files as $ file ) {
135131 $ this ->io ->write ("<info>processing</info>: {$ file ->getSourcePath ()}" );
136132 $ file ->setSourceContentFromSourcePath ();
137133
138134 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) );
143139 $ content = $ this ->sass ->compile ($ file ->getSourceContent ());
144140 break ;
145- case static ::TYPE_LESS :
141+ case File ::TYPE_LESS :
146142 $ content = $ this ->less ->compile ($ file ->getSourceContent ());
147143 break ;
148144 default :
@@ -152,4 +148,18 @@ public function processFiles($formatter)
152148 $ file ->setParsedContent ($ content );
153149 }
154150 }
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+ }
155165}
0 commit comments