Skip to content

Commit

Permalink
Update code style (#156)
Browse files Browse the repository at this point in the history
* Add Duster and update GH actions
* Update code style
* Update GitHub actions
* Update workflow name
* Update to PHP 8.2
  • Loading branch information
driftingly authored Jan 3, 2024
1 parent a52689f commit 7169143
Show file tree
Hide file tree
Showing 185 changed files with 660 additions and 573 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore

ecs.php export-ignore
duster.json export-ignore
phpstan.neon export-ignore
phpunit.xml export-ignore
stubs export-ignore
Expand Down
42 changes: 36 additions & 6 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,43 @@ on:
branches:
- main

env:
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
COMPOSER_ROOT_VERSION: "dev-main"

jobs:
code_analysis:
uses: rectorphp/reusable-workflows/.github/workflows/code_analysis.yaml@main
runs-on: ubuntu-latest

strategy:
matrix:
actions:
-
name: 'Composer Validate'
run: composer validate

-
name: 'Duster Lint'
run: composer lint

-
name: 'Rector Dry Run'
run: composer rector-dry-run

-
name: 'PHPStan'
run: composer phpstan

name: ${{ matrix.actions.name }}

steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: none

rector:
# run only on PR's from branches on main repository (from core contributors), not on the forks or PR's from forks.
if: github.event.pull_request.head.repo.full_name == github.repository && github.repository == 'driftingly/rector-laravel'
- uses: ramsey/composer-install@v2

# see https://github.com/rectorphp/reusable-workflows
uses: rectorphp/reusable-workflows/.github/workflows/rector.yaml@main
- run: ${{ matrix.actions.run }}
3 changes: 1 addition & 2 deletions .github/workflows/downgraded_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ jobs:

# downgrade /src to PHP 7.2
- run: vendor/bin/rector process src config --config build/rector-downgrade-php-72.php --ansi
- run: vendor/bin/ecs check src config --fix --ansi

# copy PHP 7.2 composer
- run: cp build/composer-php-72.json composer.json

# clear the dev files
- run: rm -rf build .github tests stubs easy-ci.php ecs.php phpstan.neon phpunit.xml
- run: rm -rf build .github tests stubs phpstan.neon phpunit.xml

# setup git user
-
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
tests:
runs-on: ubuntu-latest

name: PHP ${{ matrix.php }} tests
name: PHP Tests
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3
coverage: none

- uses: ramsey/composer-install@v2
Expand Down
13 changes: 0 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,3 @@ composer.lock

.phpunit.result.cache
.phpunit.cache

# often customized locally - example on Github is just fine
rector-recipe.php

# testing
abz

# scoped & downgraded version
php-scoper.phar
box.phar
php-parallel-lint

tmp
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
"phpstan/phpstan": "^1.8.2",
"symplify/phpstan-rules": "^11.0",
"symplify/phpstan-extensions": "^11.0",
"symplify/easy-coding-standard": "^11.0",
"symplify/rule-doc-generator": "^11.0",
"rector/phpstan-rules": "^0.6",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-webmozart-assert": "^1.1",
"phpstan/phpstan-strict-rules": "^1.2",
"symplify/vendor-patches": "^11.0"
"tightenco/duster": "^2.7"
},
"autoload": {
"psr-4": {
Expand All @@ -33,8 +32,12 @@
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify",
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi",
"check-cs": "vendor/bin/duster lint",
"fix-cs": "vendor/bin/duster fix",
"lint": "vendor/bin/duster lint",
"fix": "vendor/bin/duster fix",
"rector-dry-run": "vendor/bin/rector process --dry-run --ansi",
"rector": "vendor/bin/rector process --ansi",
"docs": [
"vendor/bin/rule-doc-generator generate src --output-file docs/rector_rules_overview.md --ansi"
]
Expand All @@ -43,7 +46,6 @@
"prefer-stable": true,
"config": {
"allow-plugins": {
"cweagans/composer-patches": true,
"rector/extension-installer": true,
"phpstan/extension-installer": true
}
Expand Down
1 change: 0 additions & 1 deletion config/sets/laravel-array-str-functions-to-static-call.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Transform\ValueObject\FuncCallToStaticCall;

Expand Down
1 change: 0 additions & 1 deletion config/sets/laravel-code-quality.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use RectorLaravel\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector;

return static function (RectorConfig $rectorConfig): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use RectorLaravel\Rector\StaticCall\EloquentMagicMethodToQueryBuilderRector;

return static function (RectorConfig $rectorConfig): void {
Expand Down
1 change: 0 additions & 1 deletion config/sets/laravel-facade-aliases-to-full-names.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Renaming\Rector\Name\RenameClassRector;

return static function (RectorConfig $rectorConfig): void {
Expand Down
1 change: 0 additions & 1 deletion config/sets/laravel-legacy-factories-to-classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use RectorLaravel\Rector\FuncCall\FactoryFuncCallToStaticCallRector;
use RectorLaravel\Rector\MethodCall\FactoryApplyingStatesRector;
use RectorLaravel\Rector\Namespace_\FactoryDefinitionRector;
Expand Down
1 change: 0 additions & 1 deletion config/sets/laravel-static-to-injection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Transform\Rector\FuncCall\FuncCallToNewRector;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
Expand Down
4 changes: 2 additions & 2 deletions config/sets/laravel100.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use RectorLaravel\Rector\Class_\UnifyModelDatesWithCastsRector;
use RectorLaravel\Rector\MethodCall\DatabaseExpressionToStringToMethodCallRector;

# see https://laravel.com/docs/10.x/upgrade
// see https://laravel.com/docs/10.x/upgrade
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

Expand All @@ -25,7 +25,7 @@

$rectorConfig
->ruleWithConfiguration(RenamePropertyRector::class, [
# https://github.com/laravel/laravel/commit/edcbe6de7c3f17070bf0ccaa2e2b785158ae5ceb
// https://github.com/laravel/laravel/commit/edcbe6de7c3f17070bf0ccaa2e2b785158ae5ceb
new RenameProperty('App\Http\Kernel', 'routeMiddleware', 'middlewareAliases'),
]);

Expand Down
5 changes: 2 additions & 3 deletions config/sets/laravel50.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;

# see: https://laravel.com/docs/5.0/upgrade
// see: https://laravel.com/docs/5.0/upgrade
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

# https://stackoverflow.com/a/24949656/1348344
// https://stackoverflow.com/a/24949656/1348344
$rectorConfig
->ruleWithConfiguration(RenameClassRector::class, [
'Illuminate\Cache\CacheManager' => 'Illuminate\Contracts\Cache\Repository',
Expand Down
3 changes: 1 addition & 2 deletions config/sets/laravel51.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Renaming\Rector\Name\RenameClassRector;

# see: https://laravel.com/docs/5.1/upgrade
// see: https://laravel.com/docs/5.1/upgrade
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
$rectorConfig
Expand Down
3 changes: 1 addition & 2 deletions config/sets/laravel52.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\Transform\ValueObject\StringToClassConstant;

# see: https://laravel.com/docs/5.2/upgrade
// see: https://laravel.com/docs/5.2/upgrade
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
$rectorConfig
Expand Down
3 changes: 1 addition & 2 deletions config/sets/laravel53.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Removing\Rector\Class_\RemoveTraitUseRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
$rectorConfig
->ruleWithConfiguration(RemoveTraitUseRector::class, [
# see https://laravel.com/docs/5.3/upgrade
// see https://laravel.com/docs/5.3/upgrade
'Illuminate\Foundation\Auth\Access\AuthorizesResources',
]);
};
5 changes: 2 additions & 3 deletions config/sets/laravel54.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\Transform\ValueObject\StringToClassConstant;

# see: https://laravel.com/docs/5.4/upgrade
// see: https://laravel.com/docs/5.4/upgrade

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
Expand Down Expand Up @@ -58,7 +57,7 @@
new MethodCallRename('Illuminate\Validation\Validator', 'addError', 'addFailure'),
new MethodCallRename('Illuminate\Validation\Validator', 'doReplacements', 'makeReplacements'),

# https://github.com/laravel/framework/commit/f23ac640fa403ca8d4131c36367b53e123b6b852
// https://github.com/laravel/framework/commit/f23ac640fa403ca8d4131c36367b53e123b6b852
new MethodCallRename(
'Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase',
'seeInDatabase',
Expand Down
3 changes: 1 addition & 2 deletions config/sets/laravel55.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameProperty;

# see: https://laravel.com/docs/5.5/upgrade
// see: https://laravel.com/docs/5.5/upgrade

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
Expand Down
3 changes: 1 addition & 2 deletions config/sets/laravel56.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Core\ValueObject\Visibility;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;

# see: https://laravel.com/docs/5.6/upgrade
// see: https://laravel.com/docs/5.6/upgrade

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
Expand Down
3 changes: 1 addition & 2 deletions config/sets/laravel57.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use PHPStan\Type\ObjectType;

use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Config\RectorConfig;
Expand All @@ -18,7 +17,7 @@
use RectorLaravel\Rector\New_\AddGuardToLoginEventRector;
use RectorLaravel\Rector\StaticCall\Redirect301ToPermanentRedirectRector;

# see: https://laravel.com/docs/5.7/upgrade
// see: https://laravel.com/docs/5.7/upgrade
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
$rectorConfig
Expand Down
17 changes: 8 additions & 9 deletions config/sets/laravel58.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use PHPStan\Type\BooleanType;

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\RenameProperty;
Expand All @@ -12,21 +11,21 @@
use RectorLaravel\Rector\Class_\PropertyDeferToDeferrableProviderToRector;
use RectorLaravel\Rector\StaticCall\MinutesToSecondsInCacheRector;

# https://laravel-news.com/laravel-5-8-deprecates-string-and-array-helpers
# https://github.com/laravel/framework/pull/26898
# see: https://laravel.com/docs/5.8/upgrade
// https://laravel-news.com/laravel-5-8-deprecates-string-and-array-helpers
// https://github.com/laravel/framework/pull/26898
// see: https://laravel.com/docs/5.8/upgrade
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/laravel-array-str-functions-to-static-call.php');
$rectorConfig->rule(MinutesToSecondsInCacheRector::class);

$rectorConfig
->ruleWithConfiguration(
AddReturnTypeDeclarationRector::class,
[new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Repository', 'put', new BooleanType()),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Repository', 'forever', new BooleanType()),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'put', new BooleanType()),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'putMany', new BooleanType()),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'forever', new BooleanType()),
[new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Repository', 'put', new BooleanType),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Repository', 'forever', new BooleanType),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'put', new BooleanType),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'putMany', new BooleanType),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'forever', new BooleanType),
]
);
$rectorConfig
Expand Down
Loading

0 comments on commit 7169143

Please sign in to comment.