Skip to content

Commit

Permalink
Add rector to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
promatik committed Apr 7, 2024
1 parent 613e076 commit 41834a9
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 30 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ jobs:
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer install --no-interaction --no-progress
- name: PHP Stan Analyse
run: composer analyse
- name: "PHP Stan Analyse"
run: "composer analyse-stan"

- name: "PHP Rector Analyse"
run: "composer analyse-rector"
11 changes: 10 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Laravel", "Backpack", "Backpack for Laravel", "Backpack Addon", "TranslationManager"
],
"require": {
"php": "^8.2|^8.3",
"backpack/crud": "^6.7",
"spatie/laravel-translation-loader": "^2.8",
"outhebox/blade-flags": "^1.2",
Expand All @@ -27,7 +28,8 @@
"require-dev": {
"phpunit/phpunit": "~10.0|~11.0",
"orchestra/testbench": "~8.0|~9.0",
"larastan/larastan": "^2.9"
"larastan/larastan": "^2.9",
"rector/rector": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -41,8 +43,15 @@
},
"scripts": {
"analyse": [
"vendor/bin/phpstan analyse",
"vendor/bin/rector --dry-run"
],
"analyse-stan": [
"vendor/bin/phpstan analyse"
],
"analyse-rector": [
"vendor/bin/rector --dry-run"
],
"test": "vendor/bin/phpunit --testdox"
},
"extra": {
Expand Down
53 changes: 53 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare (strict_types = 1);

use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
use Rector\CodeQuality\Rector\Assign\CombinedAssignRector;
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
use Rector\CodeQuality\Rector\Switch_\SingularSwitchToIfRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Switch_\RemoveDuplicatedCaseInSwitchRector;
use Rector\Php54\Rector\Array_\LongArrayToShortArrayRector;
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__DIR__.'/config',
__DIR__.'/resources',
__DIR__.'/routes',
__DIR__.'/src',
])
->withPreparedSets(
deadCode: true,
codeQuality: true,
privatization: true
)
->withPhpSets()
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
RemoveUselessReturnTagRector::class,
LongArrayToShortArrayRector::class,
])
->withSkip([
CompactToVariablesRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
ExplicitBoolCompareRector::class,
CountArrayToEmptyArrayComparisonRector::class,
SimplifyIfReturnBoolRector::class,
CombinedAssignRector::class,
InlineIfToExplicitIfRector::class,
SingularSwitchToIfRector::class,
DisallowedEmptyRuleFixerRector::class,
RemoveDuplicatedCaseInSwitchRector::class,
CallableThisArrayToAnonymousFunctionRector::class,
FirstClassCallableRector::class,
]);
10 changes: 1 addition & 9 deletions src/AutomaticServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public function __construct($app)

/**
* Boot method may be overrided by AddonServiceProvider
*
* @return void
*/
public function boot(): void
{
Expand All @@ -39,8 +37,6 @@ public function boot(): void

/**
* Perform post-registration booting of services.
*
* @return void
*/
public function autoboot(): void
{
Expand Down Expand Up @@ -86,8 +82,6 @@ public function autoboot(): void

/**
* Register any package services.
*
* @return void
*/
public function register(): void
{
Expand All @@ -98,8 +92,6 @@ public function register(): void

/**
* Console-specific booting.
*
* @return void
*/
protected function bootForConsole(): void
{
Expand Down Expand Up @@ -229,7 +221,7 @@ protected function packageDirectoryExistsAndIsNotEmpty($name)

// check if directory has files
foreach (scandir($this->path.'/'.$name) as $file) {
if ($file != '.' && $file != '..' && $file != '.gitkeep') {
if ($file !== '.' && $file !== '..' && $file !== '.gitkeep') {
return true;
}
}
Expand Down
22 changes: 8 additions & 14 deletions src/Http/Controllers/TranslationManagerCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ protected function setupListOperation(): void
'name' => 'group_key',
'label' => ucfirst(__('backpack.translation-manager::translation_manager.key')),
'type' => 'custom_html',
'value' => function (TranslationLine $entry): string {
return '<span class="badge" title="'.$entry->group_key.'">'.Str::limit($entry->group_key, 50).'</span>';
},
'value' => fn(TranslationLine $entry): string => '<span class="badge" title="'.$entry->group_key.'">'.Str::limit($entry->group_key, 50).'</span>',
'orderable' => true,
'orderLogic' => function (Builder $query, mixed $column, mixed $columnDirection): Builder {
return $query
->orderBy('group', $columnDirection)
->orderBy('key', $columnDirection);
},
'orderLogic' => fn(Builder $query, mixed $column, mixed $columnDirection): Builder => $query
->orderBy('group', $columnDirection)
->orderBy('key', $columnDirection),
'searchLogic' => function (Builder $query, mixed $column, string $search): void {
$query->orWhere('group', 'like', "%$search%")
->orWhere('key', 'like', "%$search%");
Expand Down Expand Up @@ -170,12 +166,10 @@ public function setupFilters(): void
'name' => 'group',
'type' => 'select2_multiple',
'label' => ucfirst(__('backpack.translation-manager::translation_manager.group')),
], function (): array {
return TranslationLine::select('group')
->distinct()
->pluck('group', 'group')
->toArray();
}, function (string $options): void {
], fn(): array => TranslationLine::select('group')
->distinct()
->pluck('group', 'group')
->toArray(), function (string $options): void {
CRUD::addClause('whereIn', 'group', json_decode($options));
});

Expand Down
6 changes: 3 additions & 3 deletions src/Http/Operations/CanUseEditableColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ trait CanUseEditableColumns
{
use \Backpack\EditableColumns\Http\Controllers\Operations\MinorUpdateOperation;

private $minorUpdateEntry = null;
private $minorUpdateRequest = null;
private $minorUpdateEntry;
private $minorUpdateRequest;

private function editableColumnsEnabled(): bool
{
Expand All @@ -37,7 +37,7 @@ public function saveMinorUpdateEntry()
$entry->text = $text;
$entry->save();
} else {
[$group, $key] = explode('.', $request->id);
[$group, $key] = explode('.', (string) $request->id);

TranslationLineOriginal::create([
'group' => $group,
Expand Down
2 changes: 1 addition & 1 deletion src/Models/TranslationLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getRows(): array
/**
* Boot the model.
*/
public static function boot()
public static function boot(): void
{
parent::boot();

Expand Down

0 comments on commit 41834a9

Please sign in to comment.