diff --git a/composer.json b/composer.json index c331067..2c74652 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,6 @@ "illuminate/contracts": "^10.0||^11.0" }, "require-dev": { - "laravel/pint": "^1.14", "nunomaduro/collision": "^8.1.1||^7.10.0", "larastan/larastan": "^2.9", "orchestra/testbench": "^9.0.0||^8.22.0", @@ -30,8 +29,7 @@ "pestphp/pest-plugin-laravel": "^2.3", "phpstan/extension-installer": "^1.3", "phpstan/phpstan-deprecation-rules": "^1.1", - "phpstan/phpstan-phpunit": "^1.3", - "spatie/laravel-ray": "^1.35" + "phpstan/phpstan-phpunit": "^1.3" }, "autoload": { "psr-4": { diff --git a/src/Commands/CleanCode.php b/src/Commands/CleanCode.php index cea5aed..48278c6 100644 --- a/src/Commands/CleanCode.php +++ b/src/Commands/CleanCode.php @@ -7,6 +7,7 @@ class CleanCode extends Command { public $signature = 'clean:code'; + public $description = 'Execute the code standars'; public function handle(): int diff --git a/src/Commands/OptimizeFront.php b/src/Commands/OptimizeFront.php index 9e0bd1a..95b6c76 100644 --- a/src/Commands/OptimizeFront.php +++ b/src/Commands/OptimizeFront.php @@ -8,6 +8,7 @@ class OptimizeFront extends Command { protected $signature = 'optimize:front'; + protected $description = 'Optimize Front classes'; public function handle() @@ -36,7 +37,7 @@ private function optimizeNamespace($content, $namespace, $use_new = false) $type = $type[count($type) - 1]; $models = $this->getNamespaces($content, $namespace); $namespace2 = str_replace('\\', '\\\\', $namespace); - if(count($models)==0) { + if (count($models) == 0) { return $content; } foreach ($models as $model) { @@ -44,15 +45,15 @@ private function optimizeNamespace($content, $namespace, $use_new = false) $model = str_replace('\\', '\\\\', $model); $content = preg_replace("/use $namespace2\\\\".$model.";.*\n/", '', $content); $content = preg_replace("/\b$model::/", "$type\\$model::", $content); - if($use_new) { + if ($use_new) { $content = str_replace("new $model", "new $type\\$original_model", $content); } - if(str_contains($model, '\\')) { + if (str_contains($model, '\\')) { $clean_model = explode('\\', $model); $clean_model = $clean_model[count($clean_model) - 1]; $content = preg_replace("/\b$clean_model::/", "$type\\$model::", $content); - if($use_new) { + if ($use_new) { $content = str_replace("new $clean_model", "new $type\\$original_model", $content); } } @@ -66,6 +67,7 @@ private function optimizeNamespace($content, $namespace, $use_new = false) if (! str_contains($content, "use $namespace;")) { $content = preg_replace("/namespace .*;\n/", "$0\nuse $namespace;", $content); } + return $content; } @@ -77,6 +79,7 @@ private function getNamespaces($content, $folder) foreach ($matches[2] as $match) { $namespaces[] = $match; } + return $namespaces; } } diff --git a/src/Commands/OptimizeRemovePhpDocs.php b/src/Commands/OptimizeRemovePhpDocs.php index 2ebfa43..00468e2 100644 --- a/src/Commands/OptimizeRemovePhpDocs.php +++ b/src/Commands/OptimizeRemovePhpDocs.php @@ -8,6 +8,7 @@ class OptimizeRemovePhpDocs extends Command { protected $signature = 'optimize:remove-comments'; + protected $description = 'Remove PHP Docs'; public function handle() @@ -22,23 +23,23 @@ public function handle() $comment = ''; foreach ($lines as $line) { if (strpos(trim($line), '/*') === 0) { - $comment .= $line . "\n"; + $comment .= $line."\n"; if (strpos(trim($line), '*/') !== false) { $comments[] = $comment; $comment = ''; } } elseif (strpos(trim($line), '*/') !== false) { - $comment .= $line . "\n"; + $comment .= $line."\n"; $comments[] = $comment; $comment = ''; } elseif (! empty($comment)) { - $comment .= $line . "\n"; + $comment .= $line."\n"; } } - $comments = collect($comments)->filter(function($item) { + $comments = collect($comments)->filter(function ($item) { return str_contains($item, '@'); }); - if(count($comments)==0) { + if (count($comments) == 0) { continue; } foreach ($comments as $comment) { diff --git a/src/Commands/OptimizeTraitsOnOneLine.php b/src/Commands/OptimizeTraitsOnOneLine.php index 5ec3fe5..28ddd68 100644 --- a/src/Commands/OptimizeTraitsOnOneLine.php +++ b/src/Commands/OptimizeTraitsOnOneLine.php @@ -8,6 +8,7 @@ class OptimizeTraitsOnOneLine extends Command { protected $signature = 'optimize:traits-one-line'; + protected $description = 'Put traits on one lines'; public function handle() @@ -17,31 +18,32 @@ public function handle() foreach ($files as $file) { $content = File::get($file->getPathname()); $pattern = '/[\bclass\|\btrait\]\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff ]*\s*{(([ \t\n]*use[a-zA-Z, ;]*)+)/s'; - if(! preg_match($pattern, $content)) { + if (! preg_match($pattern, $content)) { continue; } preg_match_all($pattern, $content, $matches); - $variables = collect(explode("\n", $matches[1][0]))->map(function($item) { + $variables = collect(explode("\n", $matches[1][0]))->map(function ($item) { return trim($item); })->whereNotEmpty()->values(); - if($variables->count() < 2) { + if ($variables->count() < 2) { continue; } - foreach($variables as $variable) { + foreach ($variables as $variable) { $content = preg_replace('/'.$variable.'\n[ \t]*/s', '', $content); } - $variables = $variables->map(function($item) { + $variables = $variables->map(function ($item) { $item = str_replace('use', '', $item); $item = str_replace(';', '', $item); + return explode(',', trim($item)); - })->flatten()->map(function($item) { + })->flatten()->map(function ($item) { return trim($item); })->implode(', '); $variables = "\n\tuse $variables;"; - $content = preg_replace('/[\bclass\|\btrait\]\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff ]*\s*{/s', '$0' . $variables, $content, 1); + $content = preg_replace('/[\bclass\|\btrait\]\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff ]*\s*{/s', '$0'.$variables, $content, 1); File::put($file->getPathname(), $content); } diff --git a/src/Commands/OptimizeVariablesOnOneLine.php b/src/Commands/OptimizeVariablesOnOneLine.php index 5e9b633..b0199dc 100644 --- a/src/Commands/OptimizeVariablesOnOneLine.php +++ b/src/Commands/OptimizeVariablesOnOneLine.php @@ -8,6 +8,7 @@ class OptimizeVariablesOnOneLine extends Command { protected $signature = 'optimize:variables-one-line'; + protected $description = 'Put variables on one lines'; public function handle() @@ -17,22 +18,22 @@ public function handle() foreach ($files as $file) { $content = File::get($file->getPathname()); $types = ['public', 'private', 'protected']; - foreach($types as $type) { + foreach ($types as $type) { $pattern = '/'.$type.'\s*\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)[^;]*;/s'; preg_match_all($pattern, $content, $matches); - $variables = collect($matches[0])->filter(function($item) { + $variables = collect($matches[0])->filter(function ($item) { return ! str_contains($item, '='); }); - if($variables->count() < 2) { + if ($variables->count() < 2) { continue; } $use_traits = preg_match('/[\bclass\|\btrait\]\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff ]*\s*{[ \t\n]*use[a-zA-Z, ;]*/s', $content); - foreach($variables as $variable) { + foreach ($variables as $variable) { $variable = str_replace('$', '\$', $variable); $content = preg_replace('/'.$variable.'\n[ \t]*/s', '', $content); } - $variables = $variables->map(function($item) use ($type) { + $variables = $variables->map(function ($item) use ($type) { return '$'.preg_replace('/'.$type.'\s*\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)[^;]*;/s', '$1', $item); })->implode(', '); $variables = "\n\t$type $variables;"; @@ -40,7 +41,7 @@ public function handle() if ($use_traits) { $content = preg_replace('/[\bclass\|\btrait\]\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff ]*\s*{[ \t\n]*use[a-zA-Z, ;]*\n[ \t]*/s', "$0$variables", $content, 1); } else { - $content = preg_replace('/[\bclass\|\btrait\]\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff ]*\s*{/s', '$0' . $variables, $content, 1); + $content = preg_replace('/[\bclass\|\btrait\]\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff ]*\s*{/s', '$0'.$variables, $content, 1); } } File::put($file->getPathname(), $content);