Skip to content

Commit

Permalink
refactor(rector): Run rector php74 upgrade (nunomaduro#391)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
olivernybroe authored Apr 10, 2020
1 parent 6485861 commit e96d56d
Show file tree
Hide file tree
Showing 116 changed files with 679 additions and 1,182 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
max_line_length = 80
max_line_length = 120

[*.md]
trim_trailing_whitespace = false
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ services:
- docker

php:
- 7.2
- 7.3
- 7.4

env:
Expand Down
16 changes: 10 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.4",
"ext-iconv": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-tokenizer": "*",
"composer/composer": "^1.7",
"friendsofphp/php-cs-fixer": "^2.15",
"friendsofphp/php-cs-fixer": "^2.16.1",
"justinrainbow/json-schema": "^5.1",
"league/container": "^3.2",
"object-calisthenics/phpcs-calisthenics-rules": "^3.7",
"phploc/phploc": "^5.0|^6.0",
"psr/container": "^1.0",
"sensiolabs/security-checker": "^6.0",
"slevomat/coding-standard": "^6.0",
"squizlabs/php_codesniffer": "^3.4",
"squizlabs/php_codesniffer": "^3.5",
"symfony/console": "^4.2|^5.0",
"symfony/finder": "^4.2|^5.0"
},
"require-dev": {
"ergebnis/phpstan-rules": "^0.14.0",
"illuminate/console": "^5.8|^6.0|^7.0",
"illuminate/support": "^5.8|^6.0|^7.0",
"ergebnis/phpstan-rules": "^0.14.0",
"mockery/mockery": "^1.0",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^8.0|^9.0",
"rector/rector": "^0.7.11",
"symfony/var-dumper": "^4.2|^5.0",
"symplify/easy-coding-standard": "^7.1",
"symplify/easy-coding-standard": "^7.2.3",
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
},
"suggest": {
Expand Down Expand Up @@ -73,16 +74,19 @@
"ecs:test": "ecs check src --ansi --config vendor/symplify/easy-coding-standard/config/set/clean-code.yaml",
"phpstan:test": "phpstan analyse --ansi",
"phpunit:test": "phpunit --colors=always",
"rector:test": "rector process --ansi",
"insights": "bin/phpinsights analyse --ansi -v --no-interaction",
"test": [
"@phpstan:test",
"@ecs:test",
"@rector:test --dry-run",
"@phpunit:test",
"@insights"
],
"fix": [
"@ecs:test --fix",
"@insights --fix --quiet"
"@insights --fix --quiet",
"@rector:test"
],
"post-install-cmd": [
"@website:copy-changelog",
Expand Down
6 changes: 3 additions & 3 deletions phpinsights.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

'config' => [
LineLengthSniff::class => [
'lineLimit' => 80,
'lineLimit' => 120,
'absoluteLineLimit' => 120,
'ignoreComments' => true,
],
Expand Down Expand Up @@ -118,7 +118,7 @@

'requirements' => [
'min-quality' => 90.0,
'min-architecture' => 80.0,
'min-style' => 97.8,
'min-architecture' => 85.0,
'min-style' => 98.0,
],
];
29 changes: 29 additions & 0 deletions rector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
parameters:
autoload_paths:
- 'vendor/squizlabs/php_codesniffer/autoload.php'
paths:
- 'src'
- 'tests'
- 'bin'
exclude_paths:
- 'tests/*Fixtures/*'
auto_import_names: true
php_version_features: '7.4'
sets:
- 'action-injection-to-constructor-injection'
- 'array-str-functions-to-static-call'
- 'celebrity'
- 'doctrine'
- 'phpstan'
- 'phpunit-code-quality'
- 'solid'
- 'early-return'
- 'doctrine-code-quality'
- 'dead-code'
- 'code-quality'
- 'php71'
- 'php72'
- 'php73'
- 'php74'
exclude_rectors:
- 'Rector\DeadCode\Rector\Property\RemoveNullPropertyInitializationRector'
5 changes: 2 additions & 3 deletions src/Application/Adapters/Laravel/Commands/InsightsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
use NunoMaduro\PhpInsights\Domain\Container;
use NunoMaduro\PhpInsights\Domain\Kernel;
use NunoMaduro\PhpInsights\Domain\Reflection;
use RuntimeException;
use Symfony\Component\Console\Output\ConsoleOutputInterface;

/**
* @internal
*/
final class InsightsCommand extends Command
{
/** @var string */
protected $name = 'insights';

/** @var string */
protected $description = 'Analyze the code quality';

public function handle(): int
Expand All @@ -42,7 +41,7 @@ public function handle(): int

$container = Container::make();
if (! $container instanceof \League\Container\Container) {
throw new \RuntimeException('Container should be League Container instance');
throw new RuntimeException('Container should be League Container instance');
}

$configurationDefinition = $container->extend(Configuration::class);
Expand Down
3 changes: 2 additions & 1 deletion src/Application/Adapters/Laravel/InsightsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace NunoMaduro\PhpInsights\Application\Adapters\Laravel;

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

public function boot(): void
{
if ($this->app instanceof \Illuminate\Contracts\Foundation\Application) {
if ($this->app instanceof Application) {
$this->publishes([
__DIR__.'/../../../../stubs/laravel.php' => $this->app->configPath('insights.php'),
], 'config');
Expand Down
1 change: 0 additions & 1 deletion src/Application/Adapters/Laravel/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public static function shouldBeApplied(Composer $composer): bool
$requirements = $composer->getRequirements();

foreach (array_keys($requirements) as $requirement) {
$requirement = (string) $requirement;
if (strpos($requirement, 'laravel/framework') !== false
|| strpos($requirement, 'illuminate/') !== false) {
return true;
Expand Down
57 changes: 27 additions & 30 deletions src/Application/Adapters/Magento2/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,47 @@
*/
final class Preset implements PresetContract
{
private const CONFIG = [
'exclude' => [
'bin',
'dev',
'generated',
'lib',
'phpserver',
'pub',
'setup',
'update',
'var',
'app/autoload.php',
'app/bootstrap.php',
'app/functions.php',
'index.php',
],
'add' => [
// ...
],
'remove' => [
// ...
],
'config' => [
// ...
],
];
public static function getName(): string
{
return 'magento2';
}

public static function get(Composer $composer): array
{
$config = [
'exclude' => [
'bin',
'dev',
'generated',
'lib',
'phpserver',
'pub',
'setup',
'update',
'var',
'app/autoload.php',
'app/bootstrap.php',
'app/functions.php',
'index.php',
],
'add' => [
// ...
],
'remove' => [
// ...
],
'config' => [
// ...
],
];

return ConfigResolver::mergeConfig(DefaultPreset::get($composer), $config);
return ConfigResolver::mergeConfig(DefaultPreset::get($composer), self::CONFIG);
}

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

foreach (array_keys($requirements) as $requirement) {
$requirement = (string) $requirement;

if (strpos($requirement, 'magento/magento-cloud-metapackage') !== false
|| strpos($requirement, 'magento/product-community-edition') !== false
|| strpos($requirement, 'magento/product-enterprise-edition') !== false) {
Expand Down
2 changes: 0 additions & 2 deletions src/Application/Adapters/Symfony/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public static function shouldBeApplied(Composer $composer): bool
$requirements = $composer->getRequirements();

foreach (array_keys($requirements) as $requirement) {
$requirement = (string) $requirement;

if (strpos($requirement, 'symfony/framework-bundle') !== false
|| strpos($requirement, 'symfony/flex') !== false
|| strpos($requirement, 'symfony/symfony') !== false) {
Expand Down
38 changes: 18 additions & 20 deletions src/Application/Adapters/Yii/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,38 @@
*/
final class Preset implements PresetContract
{
private const CONFIG = [
'exclude' => [
'web',
'views',
'vagrant',
'runtime',
],
'add' => [
// ...
],
'remove' => [
// ...
],
'config' => [
// ...
],
];
public static function getName(): string
{
return 'yii';
}

public static function get(Composer $composer): array
{
$config = [
'exclude' => [
'web',
'views',
'vagrant',
'runtime',
],
'add' => [
// ...
],
'remove' => [
// ...
],
'config' => [
// ...
],
];

return ConfigResolver::mergeConfig(DefaultPreset::get($composer), $config);
return ConfigResolver::mergeConfig(DefaultPreset::get($composer), self::CONFIG);
}

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

foreach (array_keys($requirements) as $requirement) {
$requirement = (string) $requirement;
if (strpos($requirement, 'yiisoft/yii2') !== false) {
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Application/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

/**
* @internal
*
* @see \Tests\Application\ComposerTest
*/
final class Composer
{
/** @var array<string, mixed> */
private $config;
private array $config;

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

public static function fromPath(string $path): self
{
return new self(json_decode((string) file_get_contents($path), true));
return new self(json_decode((string) file_get_contents($path), true, 512, JSON_THROW_ON_ERROR));
}

/**
Expand Down
Loading

0 comments on commit e96d56d

Please sign in to comment.