Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
skalero01 committed Apr 29, 2024
2 parents 4f493b5 + 2f22ace commit 6346755
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions src/Commands/CleanCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class CleanCode extends Command
{
public $signature = 'clean:code';

public $description = 'Execute the code standars';

public function handle(): int
Expand Down
11 changes: 7 additions & 4 deletions src/Commands/OptimizeFront.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class OptimizeFront extends Command
{
protected $signature = 'optimize:front';

protected $description = 'Optimize Front classes';

public function handle()
Expand Down Expand Up @@ -36,23 +37,23 @@ 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) {
$original_model = $model;
$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);
}
}
Expand All @@ -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;
}

Expand All @@ -77,6 +79,7 @@ private function getNamespaces($content, $folder)
foreach ($matches[2] as $match) {
$namespaces[] = $match;
}

return $namespaces;
}
}
11 changes: 6 additions & 5 deletions src/Commands/OptimizeRemovePhpDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class OptimizeRemovePhpDocs extends Command
{
protected $signature = 'optimize:remove-comments';

protected $description = 'Remove PHP Docs';

public function handle()
Expand All @@ -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) {
Expand Down
16 changes: 9 additions & 7 deletions src/Commands/OptimizeTraitsOnOneLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class OptimizeTraitsOnOneLine extends Command
{
protected $signature = 'optimize:traits-one-line';

protected $description = 'Put traits on one lines';

public function handle()
Expand All @@ -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);
}

Expand Down
13 changes: 7 additions & 6 deletions src/Commands/OptimizeVariablesOnOneLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class OptimizeVariablesOnOneLine extends Command
{
protected $signature = 'optimize:variables-one-line';

protected $description = 'Put variables on one lines';

public function handle()
Expand All @@ -17,30 +18,30 @@ 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;";

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);
Expand Down

0 comments on commit 6346755

Please sign in to comment.