Skip to content

Commit d1266da

Browse files
author
Eugene Matvejev
authored
Merge pull request #70 from eugene-matvejev/improve-file-processor
RC10 - improve file processor
2 parents bd4416a + 631f8b9 commit d1266da

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

src/Processor/Processor.php

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,47 @@ public function processFile(FileContainer $file)
157157
{
158158
switch ($file->getType()) {
159159
case FileContainer::TYPE_SCSS:
160-
try {
161-
$this->sass->addImportPath(dirname($file->getInputPath()));
162-
$content = $this->sass->compile($file->getInputContent());
163-
164-
return $file->setOutputContent($content);
165-
} catch (ParserException $e) {
166-
throw new CompilerException($e->getMessage(), 1, $e);
167-
}
160+
return $this->compileSCSS($file);
168161
case FileContainer::TYPE_LESS:
169-
try {
170-
return $file->setOutputContent($this->less->compileFile($file->getInputPath()));
171-
} catch (\Exception $e) {
172-
throw new CompilerException($e->getMessage(), 1, $e);
173-
}
162+
return $this->compileLESS($file);
174163
}
175164

176165
throw new CompilerException('unknown compiler');
177166
}
178167

168+
/**
169+
* @param FileContainer $file
170+
*
171+
* @return $this
172+
* @throws CompilerException
173+
*/
174+
protected function compileSCSS(FileContainer $file)
175+
{
176+
try {
177+
$this->sass->addImportPath(dirname($file->getInputPath()));
178+
$content = $this->sass->compile($file->getInputContent());
179+
180+
return $file->setOutputContent($content);
181+
} catch (ParserException $e) {
182+
throw new CompilerException($e->getMessage(), 1, $e);
183+
}
184+
}
185+
186+
/**
187+
* @param FileContainer $file
188+
*
189+
* @return $this
190+
* @throws CompilerException
191+
*/
192+
protected function compileLESS(FileContainer $file)
193+
{
194+
try {
195+
return $file->setOutputContent($this->less->compileFile($file->getInputPath()));
196+
} catch (\Exception $e) {
197+
throw new CompilerException($e->getMessage(), 1, $e);
198+
}
199+
}
200+
179201
/**
180202
* @param string $formatter
181203
*

0 commit comments

Comments
 (0)