Skip to content

Commit 7167e40

Browse files
authored
Introduce Rector tests for code quality improvement suggestions (#265)
1 parent 58ce97f commit 7167e40

File tree

5 files changed

+58
-19
lines changed

5 files changed

+58
-19
lines changed

.circleci/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ commands:
4444
name: Run code quality analysis (PHP Insights)
4545
command: php -d memory-limit=-1 ./vendor/bin/phpinsights -v --no-interaction --min-quality=100 --min-complexity=50 --min-architecture=100 --min-style=100
4646

47+
run-rector:
48+
steps:
49+
- run:
50+
name: Run code quality analysis (Rector)
51+
command: php -d memory_limit=-1 ./vendor/bin/rector process src --dry-run
52+
4753
run-phpstan:
4854
steps:
4955
- run:
@@ -75,6 +81,15 @@ jobs:
7581
steps:
7682
- setup
7783
- run-phpinsights
84+
rector:
85+
parameters:
86+
php:
87+
type: string
88+
docker:
89+
- image: php:<< parameters.php >>-cli-alpine
90+
steps:
91+
- setup
92+
- run-rector
7893
phpstan:
7994
parameters:
8095
php:
@@ -120,6 +135,10 @@ workflows:
120135
matrix:
121136
parameters:
122137
php: ["7.4", "8.0", "8.1"]
138+
- rector:
139+
matrix:
140+
parameters:
141+
php: ["7.4", "8.0", "8.1"]
123142
- phpstan:
124143
matrix:
125144
parameters:

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"pestphp/pest-plugin-laravel": "^1.2",
5252
"phpstan/phpstan-strict-rules": "^1.1",
5353
"phpunit/phpunit": "^9.5",
54+
"rector/rector": "^0.12.16",
5455
"thecodingmachine/phpstan-strict-rules": "^1.0",
5556
"wikimedia/composer-merge-plugin": "^2.0"
5657
},
@@ -93,13 +94,18 @@
9394
"scripts": {
9495
"tests": [
9596
"@tests:phpinsights",
97+
"@tests:rector",
9698
"@tests:phpstan",
9799
"@tests:pest"
98100
],
99101
"tests:phpinsights": [
100102
"Composer\\Config::disableProcessTimeout",
101103
"@php ./vendor/bin/phpinsights -v --no-interaction"
102104
],
105+
"tests:rector": [
106+
"Composer\\Config::disableProcessTimeout",
107+
"@php ./vendor/bin/rector process src --dry-run"
108+
],
103109
"tests:phpstan": [
104110
"Composer\\Config::disableProcessTimeout",
105111
"@php ./vendor/bin/phpstan analyse --ansi --memory-limit 512M"

rector.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Core\Configuration\Option;
6+
use Rector\Set\ValueObject\LevelSetList;
7+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
8+
9+
return static function (ContainerConfigurator $containerConfigurator): void {
10+
// get parameters
11+
$parameters = $containerConfigurator->parameters();
12+
$parameters->set(Option::PATHS, [
13+
__DIR__ . '/src',
14+
]);
15+
16+
// Define what rule sets will be applied
17+
$containerConfigurator->import(LevelSetList::UP_TO_PHP_74);
18+
19+
// get services (needed for register a single rule)
20+
// $services = $containerConfigurator->services();
21+
22+
// register a single rule
23+
// $services->set(TypedPropertyRector::class);
24+
25+
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, getcwd() . '/phpstan.neon.dist');
26+
};

src/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static function stringToArrayOrNull(
2020
$response = explode($delimiter, $config);
2121

2222
// @phpstan-ignore-next-line
23-
if (is_array($response) === true && count($response) >= 1 && strlen(trim($response[0])) !== '') {
23+
if (is_array($response) === true && count($response) >= 1 && strlen(trim($response[0])) !== 0) {
2424
return $response;
2525
}
2626
}

src/ServiceProvider.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,23 @@ public function configurePackage(
2222
*/
2323
public function registeringPackage(): void
2424
{
25-
app()->singleton(Auth0::class, static function (): \Auth0\Laravel\Auth0 {
26-
return new Auth0();
27-
});
25+
app()->singleton(Auth0::class, static fn (): \Auth0\Laravel\Auth0 => new Auth0());
2826

29-
app()->singleton('auth0', static function (): \Auth0\Laravel\Auth0 {
30-
return app()->make(Auth0::class);
31-
});
27+
app()->singleton('auth0', static fn (): \Auth0\Laravel\Auth0 => app()->make(Auth0::class));
3228

33-
app()->singleton(StateInstance::class, static function (): \Auth0\Laravel\StateInstance {
34-
return new StateInstance();
35-
});
29+
app()->singleton(StateInstance::class, static fn (): \Auth0\Laravel\StateInstance => new StateInstance());
3630

37-
app()->singleton(\Auth0\Laravel\Auth\User\Repository::class, static function (): \Auth0\Laravel\Auth\User\Repository {
38-
return new \Auth0\Laravel\Auth\User\Repository();
39-
});
31+
app()->singleton(\Auth0\Laravel\Auth\User\Repository::class, static fn (): \Auth0\Laravel\Auth\User\Repository => new \Auth0\Laravel\Auth\User\Repository());
4032
}
4133

4234
/**
4335
* @inheritdoc
4436
*/
4537
public function bootingPackage(): void
4638
{
47-
auth()->provider('auth0', static function ($app, array $config): \Auth0\Laravel\Auth\User\Provider {
48-
return new \Auth0\Laravel\Auth\User\Provider(app()->make($config['repository']));
49-
});
39+
auth()->provider('auth0', static fn ($app, array $config): \Auth0\Laravel\Auth\User\Provider => new \Auth0\Laravel\Auth\User\Provider(app()->make($config['repository'])));
5040

51-
auth()->extend('auth0', static function ($app, $name, array $config): \Auth0\Laravel\Auth\Guard {
52-
return new \Auth0\Laravel\Auth\Guard(auth()->createUserProvider($config['provider']), $app->make('request'));
53-
});
41+
auth()->extend('auth0', static fn ($app, $name, array $config): \Auth0\Laravel\Auth\Guard => new \Auth0\Laravel\Auth\Guard(auth()->createUserProvider($config['provider']), $app->make('request')));
5442

5543
$router = app()->make(\Illuminate\Routing\Router::class);
5644
$router->aliasMiddleware('auth0.authenticate', \Auth0\Laravel\Http\Middleware\Stateful\Authenticate::class);

0 commit comments

Comments
 (0)