Skip to content

Commit e96d56d

Browse files
authored
refactor(rector): Run rector php74 upgrade (#391)
* refactor(rector): Run rector php74 on coe * refactor(rector): Run rector with more sets and fix remaining errors * ci(rector): Remove old php versions from travis * test(rector): Fix an issue with fixtures * test(rector): Fix an issue with fixtures * ci(rector): Fix imports * Bump phpcsfixer to include a fix for visibility on properties with types
1 parent 6485861 commit e96d56d

File tree

116 files changed

+679
-1182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+679
-1182
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ insert_final_newline = true
1010
indent_style = space
1111
indent_size = 4
1212
trim_trailing_whitespace = true
13-
max_line_length = 80
13+
max_line_length = 120
1414

1515
[*.md]
1616
trim_trailing_whitespace = false

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ services:
66
- docker
77

88
php:
9-
- 7.2
10-
- 7.3
119
- 7.4
1210

1311
env:

composer.json

+10-6
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,34 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.2",
13+
"php": "^7.4",
1414
"ext-iconv": "*",
1515
"ext-json": "*",
1616
"ext-mbstring": "*",
1717
"ext-tokenizer": "*",
1818
"composer/composer": "^1.7",
19-
"friendsofphp/php-cs-fixer": "^2.15",
19+
"friendsofphp/php-cs-fixer": "^2.16.1",
2020
"justinrainbow/json-schema": "^5.1",
2121
"league/container": "^3.2",
2222
"object-calisthenics/phpcs-calisthenics-rules": "^3.7",
2323
"phploc/phploc": "^5.0|^6.0",
2424
"psr/container": "^1.0",
2525
"sensiolabs/security-checker": "^6.0",
2626
"slevomat/coding-standard": "^6.0",
27-
"squizlabs/php_codesniffer": "^3.4",
27+
"squizlabs/php_codesniffer": "^3.5",
2828
"symfony/console": "^4.2|^5.0",
2929
"symfony/finder": "^4.2|^5.0"
3030
},
3131
"require-dev": {
32+
"ergebnis/phpstan-rules": "^0.14.0",
3233
"illuminate/console": "^5.8|^6.0|^7.0",
3334
"illuminate/support": "^5.8|^6.0|^7.0",
34-
"ergebnis/phpstan-rules": "^0.14.0",
3535
"mockery/mockery": "^1.0",
3636
"phpstan/phpstan-strict-rules": "^0.12",
3737
"phpunit/phpunit": "^8.0|^9.0",
38+
"rector/rector": "^0.7.11",
3839
"symfony/var-dumper": "^4.2|^5.0",
39-
"symplify/easy-coding-standard": "^7.1",
40+
"symplify/easy-coding-standard": "^7.2.3",
4041
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
4142
},
4243
"suggest": {
@@ -73,16 +74,19 @@
7374
"ecs:test": "ecs check src --ansi --config vendor/symplify/easy-coding-standard/config/set/clean-code.yaml",
7475
"phpstan:test": "phpstan analyse --ansi",
7576
"phpunit:test": "phpunit --colors=always",
77+
"rector:test": "rector process --ansi",
7678
"insights": "bin/phpinsights analyse --ansi -v --no-interaction",
7779
"test": [
7880
"@phpstan:test",
7981
"@ecs:test",
82+
"@rector:test --dry-run",
8083
"@phpunit:test",
8184
"@insights"
8285
],
8386
"fix": [
8487
"@ecs:test --fix",
85-
"@insights --fix --quiet"
88+
"@insights --fix --quiet",
89+
"@rector:test"
8690
],
8791
"post-install-cmd": [
8892
"@website:copy-changelog",

phpinsights.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
'config' => [
5656
LineLengthSniff::class => [
57-
'lineLimit' => 80,
57+
'lineLimit' => 120,
5858
'absoluteLineLimit' => 120,
5959
'ignoreComments' => true,
6060
],
@@ -118,7 +118,7 @@
118118

119119
'requirements' => [
120120
'min-quality' => 90.0,
121-
'min-architecture' => 80.0,
122-
'min-style' => 97.8,
121+
'min-architecture' => 85.0,
122+
'min-style' => 98.0,
123123
],
124124
];

rector.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
parameters:
2+
autoload_paths:
3+
- 'vendor/squizlabs/php_codesniffer/autoload.php'
4+
paths:
5+
- 'src'
6+
- 'tests'
7+
- 'bin'
8+
exclude_paths:
9+
- 'tests/*Fixtures/*'
10+
auto_import_names: true
11+
php_version_features: '7.4'
12+
sets:
13+
- 'action-injection-to-constructor-injection'
14+
- 'array-str-functions-to-static-call'
15+
- 'celebrity'
16+
- 'doctrine'
17+
- 'phpstan'
18+
- 'phpunit-code-quality'
19+
- 'solid'
20+
- 'early-return'
21+
- 'doctrine-code-quality'
22+
- 'dead-code'
23+
- 'code-quality'
24+
- 'php71'
25+
- 'php72'
26+
- 'php73'
27+
- 'php74'
28+
exclude_rectors:
29+
- 'Rector\DeadCode\Rector\Property\RemoveNullPropertyInitializationRector'

src/Application/Adapters/Laravel/Commands/InsightsCommand.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
use NunoMaduro\PhpInsights\Domain\Container;
1313
use NunoMaduro\PhpInsights\Domain\Kernel;
1414
use NunoMaduro\PhpInsights\Domain\Reflection;
15+
use RuntimeException;
1516
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1617

1718
/**
1819
* @internal
1920
*/
2021
final class InsightsCommand extends Command
2122
{
22-
/** @var string */
2323
protected $name = 'insights';
2424

25-
/** @var string */
2625
protected $description = 'Analyze the code quality';
2726

2827
public function handle(): int
@@ -42,7 +41,7 @@ public function handle(): int
4241

4342
$container = Container::make();
4443
if (! $container instanceof \League\Container\Container) {
45-
throw new \RuntimeException('Container should be League Container instance');
44+
throw new RuntimeException('Container should be League Container instance');
4645
}
4746

4847
$configurationDefinition = $container->extend(Configuration::class);

src/Application/Adapters/Laravel/InsightsServiceProvider.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace NunoMaduro\PhpInsights\Application\Adapters\Laravel;
66

7+
use Illuminate\Contracts\Foundation\Application;
78
use Illuminate\Support\ServiceProvider;
89
use NunoMaduro\PhpInsights\Application\Adapters\Laravel\Commands\InsightsCommand;
910
use NunoMaduro\PhpInsights\Application\Injectors\Repositories;
@@ -22,7 +23,7 @@ public function register(): void
2223

2324
public function boot(): void
2425
{
25-
if ($this->app instanceof \Illuminate\Contracts\Foundation\Application) {
26+
if ($this->app instanceof Application) {
2627
$this->publishes([
2728
__DIR__.'/../../../../stubs/laravel.php' => $this->app->configPath('insights.php'),
2829
], 'config');

src/Application/Adapters/Laravel/Preset.php

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public static function shouldBeApplied(Composer $composer): bool
7777
$requirements = $composer->getRequirements();
7878

7979
foreach (array_keys($requirements) as $requirement) {
80-
$requirement = (string) $requirement;
8180
if (strpos($requirement, 'laravel/framework') !== false
8281
|| strpos($requirement, 'illuminate/') !== false) {
8382
return true;

src/Application/Adapters/Magento2/Preset.php

+27-30
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,47 @@
1414
*/
1515
final class Preset implements PresetContract
1616
{
17+
private const CONFIG = [
18+
'exclude' => [
19+
'bin',
20+
'dev',
21+
'generated',
22+
'lib',
23+
'phpserver',
24+
'pub',
25+
'setup',
26+
'update',
27+
'var',
28+
'app/autoload.php',
29+
'app/bootstrap.php',
30+
'app/functions.php',
31+
'index.php',
32+
],
33+
'add' => [
34+
// ...
35+
],
36+
'remove' => [
37+
// ...
38+
],
39+
'config' => [
40+
// ...
41+
],
42+
];
1743
public static function getName(): string
1844
{
1945
return 'magento2';
2046
}
2147

2248
public static function get(Composer $composer): array
2349
{
24-
$config = [
25-
'exclude' => [
26-
'bin',
27-
'dev',
28-
'generated',
29-
'lib',
30-
'phpserver',
31-
'pub',
32-
'setup',
33-
'update',
34-
'var',
35-
'app/autoload.php',
36-
'app/bootstrap.php',
37-
'app/functions.php',
38-
'index.php',
39-
],
40-
'add' => [
41-
// ...
42-
],
43-
'remove' => [
44-
// ...
45-
],
46-
'config' => [
47-
// ...
48-
],
49-
];
50-
51-
return ConfigResolver::mergeConfig(DefaultPreset::get($composer), $config);
50+
return ConfigResolver::mergeConfig(DefaultPreset::get($composer), self::CONFIG);
5251
}
5352

5453
public static function shouldBeApplied(Composer $composer): bool
5554
{
5655
$requirements = $composer->getRequirements();
5756

5857
foreach (array_keys($requirements) as $requirement) {
59-
$requirement = (string) $requirement;
60-
6158
if (strpos($requirement, 'magento/magento-cloud-metapackage') !== false
6259
|| strpos($requirement, 'magento/product-community-edition') !== false
6360
|| strpos($requirement, 'magento/product-enterprise-edition') !== false) {

src/Application/Adapters/Symfony/Preset.php

-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public static function shouldBeApplied(Composer $composer): bool
4747
$requirements = $composer->getRequirements();
4848

4949
foreach (array_keys($requirements) as $requirement) {
50-
$requirement = (string) $requirement;
51-
5250
if (strpos($requirement, 'symfony/framework-bundle') !== false
5351
|| strpos($requirement, 'symfony/flex') !== false
5452
|| strpos($requirement, 'symfony/symfony') !== false) {

src/Application/Adapters/Yii/Preset.php

+18-20
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,38 @@
1414
*/
1515
final class Preset implements PresetContract
1616
{
17+
private const CONFIG = [
18+
'exclude' => [
19+
'web',
20+
'views',
21+
'vagrant',
22+
'runtime',
23+
],
24+
'add' => [
25+
// ...
26+
],
27+
'remove' => [
28+
// ...
29+
],
30+
'config' => [
31+
// ...
32+
],
33+
];
1734
public static function getName(): string
1835
{
1936
return 'yii';
2037
}
2138

2239
public static function get(Composer $composer): array
2340
{
24-
$config = [
25-
'exclude' => [
26-
'web',
27-
'views',
28-
'vagrant',
29-
'runtime',
30-
],
31-
'add' => [
32-
// ...
33-
],
34-
'remove' => [
35-
// ...
36-
],
37-
'config' => [
38-
// ...
39-
],
40-
];
41-
42-
return ConfigResolver::mergeConfig(DefaultPreset::get($composer), $config);
41+
return ConfigResolver::mergeConfig(DefaultPreset::get($composer), self::CONFIG);
4342
}
4443

4544
public static function shouldBeApplied(Composer $composer): bool
4645
{
4746
$requirements = $composer->getRequirements();
4847

4948
foreach (array_keys($requirements) as $requirement) {
50-
$requirement = (string) $requirement;
5149
if (strpos($requirement, 'yiisoft/yii2') !== false) {
5250
return true;
5351
}

src/Application/Composer.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
/**
1010
* @internal
11+
*
12+
* @see \Tests\Application\ComposerTest
1113
*/
1214
final class Composer
1315
{
1416
/** @var array<string, mixed> */
15-
private $config;
17+
private array $config;
1618

1719
/**
1820
* Composer constructor.
@@ -26,7 +28,7 @@ public function __construct(array $data)
2628

2729
public static function fromPath(string $path): self
2830
{
29-
return new self(json_decode((string) file_get_contents($path), true));
31+
return new self(json_decode((string) file_get_contents($path), true, 512, JSON_THROW_ON_ERROR));
3032
}
3133

3234
/**

0 commit comments

Comments
 (0)