diff --git a/ScriptHandler.php b/ScriptHandler.php index e9da04a..ed4cfd9 100644 --- a/ScriptHandler.php +++ b/ScriptHandler.php @@ -27,8 +27,6 @@ public static function compileCSS(Event $event) $processor = new Processor($event->getIO()); - exec('rm -rf ' . __DIR__ . '/var/*'); - foreach ($configs as $config) { if (!is_array($config)) { throw new \InvalidArgumentException('The extra.css-compiler should contain only configuration objects.'); @@ -38,7 +36,7 @@ public static function compileCSS(Event $event) $processor->attachFiles(__DIR__ . "/{$value}", __DIR__ . "/{$config['output']}"); } - $processor->processFiles($config['format'] ?? 'compact'); + $processor->processFiles(isset($config['format']) ? $config['format'] : 'compact'); } $processor->saveOutput(); diff --git a/composer.json b/composer.json index e29f3f5..85e9dc2 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "eugenematvejev/css_compiler", + "name": "eugene-matvejev/css-compiler", "description": "compiles css assets from sass or less on composer events", "type": "lib", "license": "MIT", @@ -21,7 +21,7 @@ } }, "require": { - "php": ">= 7.0.4", + "php": ">= 5.5.9", "leafo/lessphp": "^0.5", "leafo/scssphp": "0.6.3 as dev-master", "leafo/scssphp-compass": "dev-master" @@ -45,7 +45,6 @@ "css-compiler": [ { "format": "compact", - "force": true, "input": [ "tests/shared-fixtures/scss" ], @@ -53,7 +52,6 @@ }, { "format": "compact", - "force": true, "input": [ "tests/shared-fixtures/sass" ], diff --git a/src/Container/File.php b/src/Container/File.php index 540a607..2f4861b 100644 --- a/src/Container/File.php +++ b/src/Container/File.php @@ -31,18 +31,27 @@ class File */ private $type; - public function __construct(string $sourcePath, string $outputPath) + /** + * @param string $sourcePath + * @param string $outputPath + */ + public function __construct($sourcePath, $outputPath) { $this->setSourcePath($sourcePath); $this->outputPath = $outputPath; } - public function getSourcePath() : string + public function getSourcePath() { return $this->sourcePath; } - public function setSourcePath(string $path) : self + /** + * @param string $path + * + * @return File + */ + public function setSourcePath($path) { $this->sourcePath = $path; $this->detectSourceTypeFromPath($path); @@ -50,62 +59,103 @@ public function setSourcePath(string $path) : self return $this; } - public function getOutputPath() : string + /** + * @return string + */ + public function getOutputPath() { return $this->outputPath; } - public function setOutputPath(string $path) : self + /** + * @param string $path + * + * @return File + */ + public function setOutputPath($path) { $this->outputPath = $path; return $this; } - public function getSourceContent() : string + /** + * @return string + */ + public function getSourceContent() { return $this->sourceContent; } - public function setSourceContent(string $content) : self + /** + * @param string $content + * + * @return File + */ + public function setSourceContent($content) { $this->sourceContent = $content; return $this; } - public function setSourceContentFromSourcePath() : self + /** + * @return File + * @throws FileException + */ + public function setSourceContentFromSourcePath() { $this->sourceContent = $this->readSourceContentByPath(); return $this; } - public function getParsedContent() : string + /** + * @return string + */ + public function getParsedContent() { return $this->parsedContent; } - public function setParsedContent(string $content) : self + /** + * @param string $content + * + * @return File + */ + public function setParsedContent($content) { $this->parsedContent = $content; return $this; } - public function getType() : string + /** + * @return string + */ + public function getType() { return $this->type; } - public function setType(string $type) : self + /** + * @param string $type + * + * @return File + */ + public function setType($type) { $this->type = $type; return $this; } - private function detectSourceTypeFromPath(string $path) + /** + * @param string $path + * + * @return void + */ + private function detectSourceTypeFromPath($path) { switch (true) { case 0 !== preg_match('/^.*\.' . static::TYPE_SCSS . '/', $path): @@ -125,6 +175,10 @@ private function detectSourceTypeFromPath(string $path) } } + /** + * @return string + * @throws FileException + */ private function readSourceContentByPath() { if (!file_exists($this->getSourcePath())) { diff --git a/src/Processor/Processor.php b/src/Processor/Processor.php index 9fbdf32..78b5380 100644 --- a/src/Processor/Processor.php +++ b/src/Processor/Processor.php @@ -50,7 +50,13 @@ protected function initCompilers() $this->compass = new CompassCompiler($this->sass); } - public function attachFiles(string $inputPath, string $outputPath) + /** + * @param string $inputPath + * @param string $outputPath + * + * @throws \Exception + */ + public function attachFiles($inputPath, $outputPath) { if (is_dir($inputPath)) { $files = scandir($inputPath); @@ -71,7 +77,10 @@ public function attachFiles(string $inputPath, string $outputPath) } } - public function concatOutput() : array + /** + * @return string[] + */ + public function concatOutput() { $outputMap = []; foreach ($this->files as $file) { @@ -85,6 +94,9 @@ public function concatOutput() : array return $outputMap; } + /** + * save output into file + */ public function saveOutput() { foreach ($this->concatOutput() as $path => $content) { @@ -100,7 +112,12 @@ public function saveOutput() } } - public function processFiles(string $formatter) + /** + * @param string $formatter + * + * @throws CompilerException + */ + public function processFiles($formatter) { switch ($formatter) { case 'compressed': @@ -135,6 +152,7 @@ public function processFiles(string $formatter) case static::TYPE_COMPASS: case static::TYPE_SCSS: case static::TYPE_SASS: + $this->sass->setFormatter($formatter); $content = $this->sass->compile($file->getSourceContent()); break; case static::TYPE_LESS: