diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..4b39d6f --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,23 @@ +exclude([ + 'runtime', + 'vendor', + ]) + ->in(__DIR__ . '/lib'); + +$rules = [ + '@Symfony' => true, + 'phpdoc_inline_tag' => false, + 'single_import_per_statement' => false, + 'concat_space' => ['spacing' => 'one'], + 'array_syntax' => ['syntax' => 'short'], + 'phpdoc_no_package' => false, +]; + +if (class_exists('\\PhpCsFixer\\Fixer\\ControlStructure\\YodaStyleFixer')) { + $rules['yoda_style'] = false; +} + +return PhpCsFixer\Config::create()->setRules($rules)->setFinder($finder); diff --git a/composer.json b/composer.json index 06a95ac..80f9db6 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "symfony/console": "^3.2" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^2.16@dev" }, "autoload": { "psr-4": { diff --git a/lib/Handler/HandlerInterface.php b/lib/Handler/HandlerInterface.php index 9d3feed..8dcd9da 100644 --- a/lib/Handler/HandlerInterface.php +++ b/lib/Handler/HandlerInterface.php @@ -15,14 +15,12 @@ interface HandlerInterface */ public function canHandleFile($file); - /** - * Записывает файл в очередь на обработку. - * - * @param string $file Путь к файлу - * - * @return void - */ - public function queueFile($file); + /** + * Записывает файл в очередь на обработку. + * + * @param string $file Путь к файлу + */ + public function queueFile($file); /** * Обрабатывает файлы в очереди. diff --git a/lib/Handler/HandlerProcessor.php b/lib/Handler/HandlerProcessor.php index cb20fd3..a52bd6b 100644 --- a/lib/Handler/HandlerProcessor.php +++ b/lib/Handler/HandlerProcessor.php @@ -7,7 +7,7 @@ class HandlerProcessor /** @var array Стандартные обработчики */ private $defaultHandlers = [ 'image' => '\\Dumkaaa\\BxOptimize\\Handler\\ImageHandler', - 'css' => '\\Dumkaaa\\BxOptimize\\Handler\\CssHandler', + 'css' => '\\Dumkaaa\\BxOptimize\\Handler\\CssHandler', ]; /** @var array Включенные обработчики */ @@ -17,6 +17,8 @@ class HandlerProcessor * Включаем либо обработчики из переданного набора, либо все стандартные. * * @param array $handlers + * + * @throws \Exception */ public function __construct(array $handlers) { @@ -29,6 +31,8 @@ public function __construct(array $handlers) * Включает обработчики из массива. * * @param array $handlers + * + * @throws \Exception */ public function enableHandlers(array $handlers) { diff --git a/lib/Handler/HandlerTools.php b/lib/Handler/HandlerTools.php index a044cf0..84b8576 100644 --- a/lib/Handler/HandlerTools.php +++ b/lib/Handler/HandlerTools.php @@ -1,72 +1,68 @@ [ - "gif" => "gifsicle.exe", - "png" => "optipng.exe", - "jpg" => "jpegtran.exe", - "jpeg" => "jpegtran.exe", - "pngquant" => "pngquant.exe", - "webp" => "cwebp.exe", + 'win' => [ + 'gif' => 'gifsicle.exe', + 'png' => 'optipng.exe', + 'jpg' => 'jpegtran.exe', + 'jpeg' => 'jpegtran.exe', + 'pngquant' => 'pngquant.exe', + 'webp' => 'cwebp.exe', ], - "darwin" => [ - "gif" => "gifsicle-mac", - "png" => "optipng-mac", - "jpg" => "jpegtran-mac", - "jpeg" => "jpegtran-mac", - "pngquant" => "pngquant-mac", - "webp" => "cwebp-mac9", + 'darwin' => [ + 'gif' => 'gifsicle-mac', + 'png' => 'optipng-mac', + 'jpg' => 'jpegtran-mac', + 'jpeg' => 'jpegtran-mac', + 'pngquant' => 'pngquant-mac', + 'webp' => 'cwebp-mac9', ], - "sunos" => [ - "gif" => "gifsicle-sol", - "png" => "optipng-sol", - "jpg" => "jpegtran-sol", - "jpeg" => "jpegtran-sol", - "pngquant" => "pngquant-sol", - "webp" => "cwebp-sol", + 'sunos' => [ + 'gif' => 'gifsicle-sol', + 'png' => 'optipng-sol', + 'jpg' => 'jpegtran-sol', + 'jpeg' => 'jpegtran-sol', + 'pngquant' => 'pngquant-sol', + 'webp' => 'cwebp-sol', ], - "freebsd" =>[ - "gif" => "gifsicle-fbsd", - "png" => "optipng-fbsd", - "jpg" => "jpegtran-fbsd", - "jpeg" => "jpegtran-fbsd", - "pngquant" => "pngquant-fbsd", - "webp" => "cwebp-fbsd", + 'freebsd' => [ + 'gif' => 'gifsicle-fbsd', + 'png' => 'optipng-fbsd', + 'jpg' => 'jpegtran-fbsd', + 'jpeg' => 'jpegtran-fbsd', + 'pngquant' => 'pngquant-fbsd', + 'webp' => 'cwebp-fbsd', ], - "linux" => [ - "gif" => "gifsicle-linux", - "png" => "optipng-linux", - "jpg" => "jpegtran-linux", - "jpeg" => "jpegtran-linux", - "pngquant" => "pngquant-linux", - "webp" => "cwebp-linux", + 'linux' => [ + 'gif' => 'gifsicle-linux', + 'png' => 'optipng-linux', + 'jpg' => 'jpegtran-linux', + 'jpeg' => 'jpegtran-linux', + 'pngquant' => 'pngquant-linux', + 'webp' => 'cwebp-linux', ], ]; - public static function getBinaryHandler($type) { - + public static function getBinaryHandler($type) + { $handlers = self::getBinaryHandlers(); $handlerPath = dirname(dirname(__DIR__)) . '/bin/'; return isset($handlers[$type]) ? $handlerPath . $handlers[$type] : false; - } - public static function getBinaryHandlers() { - + public static function getBinaryHandlers() + { $os = strtolower(PHP_OS); - if (substr($os, 0, 3) == "win") { - $os = "win"; + if (substr($os, 0, 3) == 'win') { + $os = 'win'; } return isset(self::$handlers[$os]) ? self::$handlers[$os] : []; } - -} \ No newline at end of file +} diff --git a/lib/Handler/ImageHandler.php b/lib/Handler/ImageHandler.php index 68162fb..4a057c1 100644 --- a/lib/Handler/ImageHandler.php +++ b/lib/Handler/ImageHandler.php @@ -27,27 +27,24 @@ public function handleQueue() } foreach ($this->files as $file) { - $command = false; $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if ($handlers[$ext]) { - switch ($ext) { case 'png': $command = sprintf($this->args[$ext], escapeshellarg($file)); break; case 'jpg': case 'jpeg': - $command = sprintf($this->args[$ext], escapeshellarg($file), escapeshellarg($file . ".original")); + $command = sprintf($this->args[$ext], escapeshellarg($file), escapeshellarg($file . '.original')); break; } - if (!file_exists($file . ".original") && $command) { - copy($file, $file . ".original"); + if (!file_exists($file . '.original') && $command) { + copy($file, $file . '.original'); exec($handlers[$ext] . $command); } - } else { echo "Не найден бинарный обработчик для файла: $file\n"; } diff --git a/lib/Install/Installer.php b/lib/Install/Installer.php index 326f439..74b7c6b 100644 --- a/lib/Install/Installer.php +++ b/lib/Install/Installer.php @@ -7,9 +7,9 @@ class Installer { protected static $tools = [ - 'gif' => 'gifsicle', - 'png' => 'optipng', - 'jpg' => 'jpegtran', + 'gif' => 'gifsicle', + 'png' => 'optipng', + 'jpg' => 'jpegtran', 'pngquant' => 'pngquant', ];