Skip to content

Upgrade dependencies (PHP-CS-Fixer v3) #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/frameworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
os: [ubuntu-latest]
version: ['^4.4', '@stable', '@dev'] # Test current LTS, current release, and future release
php: ['7.4', '8.0']
composer-version: [v1, v2]
composer-version: [v2]
exclude:
- version: '^4.4'
php: '8.0'
Expand Down Expand Up @@ -44,7 +44,6 @@ jobs:
run: |
composer config name phpinsights/symfony-tester
composer config description "Symfony test"
composer require composer/composer:^${{ matrix.composer-version }}
continue-on-error: ${{ env.allow_failure == 'true' }}
- name: Linking library
working-directory: ./project
Expand All @@ -60,7 +59,7 @@ jobs:
- name: Install PHPInsights
working-directory: ./project
run: composer require --dev "nunomaduro/phpinsights:*" -n --ansi
continue-on-error: ${{ env.allow_failure == 'true' }}
continue-on-error: true
- name: Launch PHPInsights
working-directory: ./project
run: php vendor/bin/phpinsights -n --disable-security-check --ansi
Expand All @@ -77,7 +76,7 @@ jobs:
os: [ubuntu-latest]
version: ['^7.0', '^8.0']
php: ['7.4', '8.0']
composer-version: [v1, v2]
composer-version: [v2]
exclude:
- version: '^7.0'
php: '8.0'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/standalone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
php: ['7.4', '8.0']
dependency-version: [prefer-lowest, prefer-stable]
composer-version: [v1, v2]
composer-version: [v2]
exclude:
- dependency-version: prefer-lowest
php: '8.0'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
php: ['7.4', '8.0']
dependency-version: [prefer-lowest, prefer-stable]
composer-version: [ v1, v2 ]
composer-version: [ v2 ]
exclude:
- dependency-version: prefer-lowest
php: '8.0'
Expand Down
7 changes: 7 additions & 0 deletions bin/phpinsights
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ declare(strict_types=1);
use NunoMaduro\PhpInsights\Domain\Kernel;
use Symfony\Component\Console\Application;

if (!defined('T_MATCH')) {
// Avoid conflict using php-codesniffer and php-cs-fixer together.
// codesniffer register this constant with string, cs-fixer v3 expect it as int
// @TODO: Drop when require PHP8.0+
define('T_MATCH', 341);
}

(static function () {
require file_exists(__DIR__ . '/../vendor/autoload.php')
? __DIR__ . '/../vendor/autoload.php'
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"ext-json": "*",
"ext-mbstring": "*",
"ext-tokenizer": "*",
"composer/composer": "^1.7 || ^2.0",
"friendsofphp/php-cs-fixer": "^2.16.1",
"composer/composer": "^2.0",
"friendsofphp/php-cs-fixer": "^3.0.0",
"justinrainbow/json-schema": "^5.1",
"league/container": "^3.2",
"php-parallel-lint/php-parallel-lint": "^1.3",
Expand All @@ -44,7 +44,7 @@
"mockery/mockery": "^1.0",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^8.0|^9.0",
"rector/rector": "^0.10.6",
"rector/rector": "^0.11.2",
"symfony/var-dumper": "^4.2|^5.0",
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
},
Expand Down Expand Up @@ -79,7 +79,7 @@
"scripts": {
"website:copy-changelog": "@php -r \"copy('CHANGELOG.md', 'docs/changelog.md');\"",
"website:copy-logo": "@php -r \"(is_dir('docs/.vuepress/public') || mkdir('docs/.vuepress/public')) && copy('art/logo_mixed.gif', 'docs/.vuepress/public/logo.gif') && copy('art/heart.svg', 'docs/.vuepress/public/heart.svg') && copy('art/heart.png', 'docs/.vuepress/public/heart.png');\"",
"csfixer:test": "php-cs-fixer fix -v --diff-format udiff",
"csfixer:test": "php-cs-fixer fix -v",
"phpstan:test": "phpstan analyse --ansi",
"phpunit:test": "phpunit --colors=always",
"rector:test": "rector process --ansi",
Expand Down Expand Up @@ -108,12 +108,12 @@
"scripts-descriptions": {
"website:copy-changelog": "Copy package changelog to the website",
"website:copy-logo": "Copy logo from art directory to the website",
"ecs:test": "Run the ecs tests.",
"rector:test": "Run the rector tests.",
"csfixer:test": "Run the PhpCsFixer tests.",
"phpstan:test": "Run the phpstan tests.",
"phpunit:test": "Run the phpunit tests.",
"insights": "Run the phpinsights tests",
"test": "Run all tests including phpstan, phpunit and ecs.",
"test": "Run all tests including phpstan, phpunit and phpcs.",
"fix": "Run ecs, phpinsights and rector fixers."
}
}
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ parameters:
message: '#generic class ReflectionClass#'
path: src/Domain/Reflection.php
- '#NunoMaduro\\PhpInsights\\Domain\\File::addFixableError#'
- '#NunoMaduro\\PhpInsights\\Domain\\Differ#'
- '#iterable type PhpCsFixer\\Tokenizer\\Tokens#'
- '#Method NunoMaduro\\PhpInsights\\Application\\Console\\Definitions\\BaseDefinition::get\(\) is not final#'
-
Expand All @@ -52,7 +53,7 @@ parameters:
message: "#^Parameter \\#.* of class Composer\\\\Package\\\\Locker constructor expects .*$#"
count: 3
path: src/Domain/ComposerLoader.php

- "#^Parameter \\#1 \\$input of function array_flip expects array\\<int\\|string\\>, array\\<string, array\\|float\\|int\\|string\\> given\\.$#"
bootstrapFiles:
- %rootDir%/../../squizlabs/php_codesniffer/autoload.php
reportUnmatchedIgnoredErrors: false
Expand Down
3 changes: 0 additions & 3 deletions src/Application/Adapters/Laravel/Commands/InsightsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public function handle(): int
}

$configuration = require $configPath;
/**
* @noRector Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector
*/
$configuration['fix'] = $this->hasOption('fix') && (bool) $this->option('fix') === true;
try {
$configuration = ConfigResolver::resolve($configuration, $this->input);
Expand Down
3 changes: 0 additions & 3 deletions src/Application/Injectors/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public function __invoke(): array
$config = require $configPath;
}

/**
* @noRector Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector
*/
$fixOption = $input->hasOption('fix') && (bool) $input->getOption('fix') === true;

$config['fix'] = $fixOption || $input->getFirstArgument() === 'fix';
Expand Down
9 changes: 1 addition & 8 deletions src/Domain/ComposerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Composer\IO\NullIO;
use Composer\Json\JsonFile;
use Composer\Package\Locker;
use Composer\Repository\RepositoryManager;

/**
* @internal
Expand Down Expand Up @@ -49,12 +48,6 @@ private static function getLocker(string $composerPath, NullIO $io): Locker
throw new \InvalidArgumentException('Unable to get content of ' . $composerPath);
}

$lockerConstructor = new \ReflectionMethod(Locker::class, '__construct');

// In composer v2, RepositoryManager is no longer needed
/** @phpstan-ignore-next-line */
return $lockerConstructor->getParameters()[2]->getType()->getName() === RepositoryManager::class
? new Locker($io, new JsonFile($lockFile, null, $io), self::$composer->getRepositoryManager(), self::$composer->getInstallationManager(), $composerContent)
: new Locker($io, new JsonFile($lockFile, null, $io), self::$composer->getInstallationManager(), $composerContent);
return new Locker($io, new JsonFile($lockFile, null, $io), self::$composer->getInstallationManager(), $composerContent);
}
}
6 changes: 3 additions & 3 deletions src/Domain/Differ.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace NunoMaduro\PhpInsights\Domain;

use PhpCsFixer\Diff\v3_0\Differ as BaseDiffer;
use PhpCsFixer\Diff\v3_0\Output\StrictUnifiedDiffOutputBuilder;
use PhpCsFixer\Diff\Differ as BaseDiffer;
use PhpCsFixer\Diff\Output\StrictUnifiedDiffOutputBuilder;
use PhpCsFixer\Differ\DifferInterface;

final class Differ implements DifferInterface
Expand All @@ -30,7 +30,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function diff($old, $new): string
public function diff(string $old, string $new, ?\SplFileInfo $file = null): string
{
return $this->differ->diff($old, $new);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return $this->differ->diff($old, $new);
return $this->differ->diff($old, $new, $file);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jibbarth It seems like they have changed the signature of the differ. So, if we're gonna use the third parameter ($file), we need to pass one parameter from the LongestCommonSubsequenceCalculator type. WDYT?

}
Expand Down
6 changes: 6 additions & 0 deletions src/Domain/Insights/FixerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use NunoMaduro\PhpInsights\Domain\Details;
use NunoMaduro\PhpInsights\Domain\Helper\Files;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Tokens;
use SplFileInfo;

Expand Down Expand Up @@ -138,6 +139,11 @@ public function addDiff(string $file, string $diff): void
$this->errors[] = Details::make()->setFile($file)->setDiff($diff)->setMessage($diff);
}

public function getDefinition(): FixerDefinitionInterface
{
return $this->fixer->getDefinition();
}

private function skipFilesFromExcludedFiles(SplFileInfo $file): bool
{
$path = $file->getRealPath();
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Metrics/Style/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
use PhpCsFixer\Fixer\Operator\StandardizeNotEqualsFixer;
use PhpCsFixer\Fixer\Phpdoc\AlignMultilineCommentFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagNormalizerFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer;
use PhpCsFixer\Fixer\PhpTag\FullOpeningTagFixer;
Expand Down Expand Up @@ -181,7 +181,7 @@ public function getInsights(): array
SingleQuoteFixer::class,
StandardizeNotEqualsFixer::class,
PhpdocIndentFixer::class,
PhpdocInlineTagFixer::class,
PhpdocInlineTagNormalizerFixer::class,
PhpdocTrimFixer::class,
PhpdocVarAnnotationCorrectOrderFixer::class,
SingleClassElementPerStatementFixer::class,
Expand Down