Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: facile-it/facile-coding-standard
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.2.0
Choose a base ref
...
head repository: facile-it/facile-coding-standard
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.3.0
Choose a head ref

Commits on Feb 6, 2024

  1. Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c5aeeb5 View commit details
  2. Map new rules from 3.49.0

    Jean85 committed Feb 6, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    61edee9 View commit details
  3. Bump ramsey/composer-install from 1 to 2

    Bumps [ramsey/composer-install](https://github.com/ramsey/composer-install) from 1 to 2.
    - [Release notes](https://github.com/ramsey/composer-install/releases)
    - [Commits](ramsey/composer-install@v1...v2)
    
    ---
    updated-dependencies:
    - dependency-name: ramsey/composer-install
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and Jean85 committed Feb 6, 2024
    Copy the full SHA
    a54e1ef View commit details
  4. Merge pull request #68 from facile-it/dependabot/github_actions/ramse…

    …y/composer-install-2
    
    Bump ramsey/composer-install from 1 to 2
    Jean85 authored Feb 6, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    af6eb02 View commit details
  5. Bump actions/checkout from 2 to 4

    Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 4.
    - [Release notes](https://github.com/actions/checkout/releases)
    - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
    - [Commits](actions/checkout@v2...v4)
    
    ---
    updated-dependencies:
    - dependency-name: actions/checkout
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and Jean85 committed Feb 6, 2024
    Copy the full SHA
    27dcdd7 View commit details
  6. Merge pull request #66 from facile-it/dependabot/github_actions/actio…

    …ns/checkout-4
    
    Bump actions/checkout from 2 to 4
    Jean85 authored Feb 6, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    44f2b4a View commit details
  7. Bump codecov/codecov-action from 3 to 4

    Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
    - [Release notes](https://github.com/codecov/codecov-action/releases)
    - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
    - [Commits](codecov/codecov-action@v3...v4)
    
    ---
    updated-dependencies:
    - dependency-name: codecov/codecov-action
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and Jean85 committed Feb 6, 2024
    Copy the full SHA
    c109d94 View commit details
  8. Merge pull request #67 from facile-it/dependabot/github_actions/codec…

    …ov/codecov-action-4
    
    Bump codecov/codecov-action from 3 to 4
    Jean85 authored Feb 6, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b21bf25 View commit details

Commits on Feb 29, 2024

  1. Map new rule as undesidered

    Jean85 committed Feb 29, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    6dbd845 View commit details

Commits on Mar 4, 2024

  1. Bump ramsey/composer-install from 2 to 3

    Bumps [ramsey/composer-install](https://github.com/ramsey/composer-install) from 2 to 3.
    - [Release notes](https://github.com/ramsey/composer-install/releases)
    - [Commits](ramsey/composer-install@v2...v3)
    
    ---
    updated-dependencies:
    - dependency-name: ramsey/composer-install
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Mar 4, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d6c8292 View commit details
  2. Merge pull request #69 from facile-it/dependabot/github_actions/ramse…

    …y/composer-install-3
    
    Bump ramsey/composer-install from 2 to 3
    Jean85 authored Mar 4, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    8bd4e5c View commit details

Commits on Mar 17, 2024

  1. Add Dependabot for PHP deps

    Jean85 authored Mar 17, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    063866f View commit details
  2. Update vimeo/psalm requirement from ^4.9 to ^5.23

    Updates the requirements on [vimeo/psalm](https://github.com/vimeo/psalm) to permit the latest version.
    - [Release notes](https://github.com/vimeo/psalm/releases)
    - [Commits](vimeo/psalm@4.9.0...5.23.1)
    
    ---
    updated-dependencies:
    - dependency-name: vimeo/psalm
      dependency-type: direct:development
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Mar 17, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ed44abd View commit details

Commits on Mar 18, 2024

  1. Resolve new Psalm errors

    Jean85 committed Mar 18, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    b2d4f66 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    7737e19 View commit details
  3. Fix more Psalm errors

    Jean85 committed Mar 18, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    64e457b View commit details
  4. Add test to improve coverage

    Jean85 committed Mar 18, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    929279c View commit details
  5. Merge pull request #70 from facile-it/dependabot/composer/vimeo/psalm…

    …-tw-5.23
    
    Update vimeo/psalm requirement from ^4.9 to ^5.23
    Jean85 authored Mar 18, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    e958854 View commit details

Commits on Mar 25, 2024

  1. Update psalm/plugin-phpunit requirement from ^0.18.4 to ^0.19.0

    Updates the requirements on [psalm/plugin-phpunit](https://github.com/psalm/psalm-plugin-phpunit) to permit the latest version.
    - [Release notes](https://github.com/psalm/psalm-plugin-phpunit/releases)
    - [Commits](psalm/psalm-plugin-phpunit@0.18.4...0.19.0)
    
    ---
    updated-dependencies:
    - dependency-name: psalm/plugin-phpunit
      dependency-type: direct:development
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Mar 25, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    22ee06e View commit details
  2. Merge pull request #71 from facile-it/dependabot/composer/psalm/plugi…

    …n-phpunit-tw-0.19.0
    
    Update psalm/plugin-phpunit requirement from ^0.18.4 to ^0.19.0
    Jean85 authored Mar 25, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4bb4145 View commit details

Commits on Apr 15, 2024

  1. Allow overriding of trailing_comma_in_multiline

    Jean85 committed Apr 15, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    2db63c8 View commit details
  2. Merge pull request #73 from facile-it/fix-ci

    Allow overriding of `trailing_comma_in_multiline`
    Jean85 authored Apr 15, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c61ab59 View commit details

Commits on Apr 22, 2024

  1. List new php_unit_attributes in tests

    Jean85 committed Apr 22, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    9088c64 View commit details

Commits on May 6, 2024

  1. Put new ordered_attributes rule as to be discussed

    Jean85 committed May 6, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    887e1f2 View commit details

Commits on Oct 11, 2024

  1. Enable parallel execution

    Jean85 committed Oct 11, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    1d307ea View commit details
  2. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    663e67c View commit details
  3. Map new rule

    Jean85 committed Oct 11, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    e8d26bd View commit details
  4. Fix CS

    Jean85 committed Oct 11, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    74e03cd View commit details
  5. Reduce CI jobs by running just one --prefer-lowest

    Jean85 committed Oct 11, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    f129bc1 View commit details
  6. Check rules against PER-CS first

    Jean85 committed Oct 11, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    30f1441 View commit details
  7. Merge pull request #75 from facile-it/fix-build

    Fix build
    Jean85 authored Oct 11, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    777ba4d View commit details
  8. Allow PHPUnit 10

    Jean85 committed Oct 11, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    be29eeb View commit details
  9. Rename abstract test to avoid it being loaded as a test

    Jean85 committed Oct 11, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    f8c1f29 View commit details
  10. Merge pull request #76 from facile-it/allow-phpunit-10

    Allow PHPUnit 10
    Jean85 authored Oct 11, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3e6f72a View commit details
  11. Drop support to Composer 1

    Jean85 committed Oct 11, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    040b679 View commit details
  12. Add changelog entry

    Jean85 committed Oct 11, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    3750f75 View commit details
  13. Merge pull request #77 from facile-it/drop-composer-1

    Drop support to Composer 1
    Jean85 authored Oct 11, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d353535 View commit details

Commits on Nov 6, 2024

  1. Test against PHP 8.4

    Jean85 committed Nov 6, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    c067bd8 View commit details
  2. Fix PHP 8.4 deprecation

    Jean85 committed Nov 6, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    719acd9 View commit details
  3. Add changelog entry

    Jean85 committed Nov 6, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    3003371 View commit details

Commits on Nov 7, 2024

  1. Change approach in how PHP 8.4 is installed in CI

    Jean85 committed Nov 7, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    82bf842 View commit details
  2. Ignore PHP constraints in E2E test due to PHP 8.4 testing

    Jean85 committed Nov 7, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Jean85 Alessandro Lai
    Copy the full SHA
    ae7979a View commit details
  3. Merge pull request #74 from facile-it/php-8.4

    PHP 8.4 support
    Jean85 authored Nov 7, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5f3c085 View commit details
11 changes: 11 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 103
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: weekly
23 changes: 16 additions & 7 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -23,12 +23,19 @@ jobs:
- "8.2"
- "8.3"
deps:
- "lowest"
- "highest"
composer-options:
- "--prefer-dist"
include:
- php-version: "7.4"
deps: "lowest"
- php-version: "8.4"
composer-options: "--prefer-dist --ignore-platform-req=php+"


steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

@@ -40,16 +47,16 @@ jobs:
ini-values: "zend.assertions=1"

- name: "Install dependencies"
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.deps }}
composer-options: --prefer-dist
composer-options: ${{ matrix.composer-options }}

- name: "Run PHPUnit"
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"

- name: "Upload coverage"
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: './coverage.xml'
fail_ci_if_error: true
@@ -58,12 +65,14 @@ jobs:
- name: "Run PHP-CS-Fixer (E2E test)"
run: "vendor/bin/php-cs-fixer fix --dry-run --diff"
if: "${{ matrix.deps != 'lowest' }}"
env:
PHP_CS_FIXER_IGNORE_ENV: true
Psalm:
name: "Psalm"
runs-on: "ubuntu-20.04"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

@@ -73,7 +82,7 @@ jobs:
php-version: "8.0"

- name: "Install dependencies"
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v3

- name: "Run Psalm"
run: "vendor/bin/psalm"
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
$rulesProvider = new Facile\CodingStandards\Rules\CompositeRulesProvider($providers);

$config = new PhpCsFixer\Config('facile-it/facile-coding-standard');
$config->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect());
$config->setRules($rulesProvider->getRules());

$config->setUsingCache(true);
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
---------
- Add PHP 8.4 support (#74)

## [1.3.0] - TBA
- Drop support to Composer 1.x (#77)

## [1.2.0] - 2024-01-22
- Add new `numeric_literal_separator` rule (#65)
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -21,20 +21,20 @@
"require": {
"php": "^7.4 || ^8.0",
"ext-json": "*",
"composer-plugin-api": "^1.1 || ^2.0",
"composer-plugin-api": "^2.0",
"friendsofphp/php-cs-fixer": "^3.4",
"symfony/console": "^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/polyfill-php80": "^1.0"
},
"require-dev": {
"composer/composer": "^1.3.2 || ^2.0",
"composer/composer": "^2.0",
"composer/semver": "^3.0",
"mikey179/vfsstream": "^1.6.8",
"phpspec/prophecy": "^1.10",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5.28",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^4.9"
"phpunit/phpunit": "^9.5.28 || ^10.5.36",
"psalm/plugin-phpunit": "^0.19.0",
"vimeo/psalm": "^5.23"
},
"autoload": {
"psr-4": {
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@
<psalm
errorLevel="1"
resolveFromConfigFile="true"
findUnusedBaselineEntry="true"
findUnusedCode="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
15 changes: 13 additions & 2 deletions src/AutoloadPathProvider.php
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@ class AutoloadPathProvider

public function __construct(?string $composerFile = null, ?string $projectRoot = null, bool $dev = true)
{
$this->composerPath = $composerFile ?: trim(getenv('COMPOSER') ?: '') ?: './composer.json';
$this->composerPath = $composerFile ?? $this->getComposerFilePath();

$projectRootPath = $projectRoot ?: realpath(\dirname($this->composerPath));
$projectRootPath = $projectRoot ?? realpath(\dirname($this->composerPath));

if (false === $projectRootPath) {
throw new \RuntimeException('Unable to get project root.');
@@ -35,6 +35,17 @@ public function __construct(?string $composerFile = null, ?string $projectRoot =
$this->dev = $dev;
}

private function getComposerFilePath(): string
{
$path = getenv('COMPOSER');

if (\is_string($path) && $path !== '') {
return trim($path);
}

return './composer.json';
}

/**
* @return string[]
*/
20 changes: 13 additions & 7 deletions src/Installer/Installer.php
Original file line number Diff line number Diff line change
@@ -41,6 +41,8 @@ class Installer
private $phpCsWriter;

/**
* @psalm-suppress PossiblyUnusedParam
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*/
@@ -55,9 +57,9 @@ public function __construct(
// Get composer.json location
$composerFile = $composerPath ?? Factory::getComposerFile();
// Calculate project root from composer.json, if necessary
$projectRootPath = $projectRoot ?: realpath(\dirname($composerFile));
$projectRootPath = $projectRoot ?? realpath(\dirname($composerFile));

if (! $projectRootPath) {
if ($projectRootPath === false) {
throw new \RuntimeException('Unable to get project root.');
}

@@ -96,7 +98,7 @@ public function checkUpgrade(PackageInterface $currentPackage, PackageInterface

$question = [
' <error>You are upgrading "' . $currentPackage->getPrettyName() . '" with possible BC breaks.</error>',
sprintf(
\sprintf(
' <question>%s</question>',
'Do you want to write the new configuration? (Y/n)'
),
@@ -133,6 +135,10 @@ private function isBcBreak(PackageInterface $currentPackage, PackageInterface $t
return true;
}

/**
* @psalm-suppress PossiblyUnusedMethod
* @psalm-suppress PossiblyUnusedParam
*/
public function setPhpCsWriter(PhpCsConfigWriterInterface $phpCsWriter): void
{
$this->phpCsWriter = $phpCsWriter;
@@ -162,7 +168,7 @@ public function requestCreateCsConfig(): void
}

$question = [
sprintf(
\sprintf(
" <question>%s</question>\n",
'Do you want to create the CS configuration in your project root? (Y/n)'
),
@@ -197,7 +203,7 @@ public function requestAddComposerScripts(): void
}

$question = [
sprintf(
\sprintf(
" <question>%s</question>\n",
'Do you want to add scripts to composer.json? (Y/n)'
),
@@ -220,9 +226,9 @@ public function requestAddComposerScripts(): void
foreach ($scripts as $key => $command) {
if (isset($this->composerDefinition['scripts'][$key]) && $this->composerDefinition['scripts'][$key] !== $command) {
$this->io->write([
sprintf(' <error>Another script "%s" exists!</error>', $key),
\sprintf(' <error>Another script "%s" exists!</error>', $key),
' If you want, you can replace it manually with:',
sprintf("\n <comment>\"%s\": \"%s\"</comment>", $key, $command),
\sprintf("\n <comment>\"%s\": \"%s\"</comment>", $key, $command),
]);
continue;
}
2 changes: 1 addition & 1 deletion src/Installer/Plugin.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ class Plugin implements EventSubscriberInterface, PluginInterface, Capable
*
* Optionally accept the project root into which to install.
*/
public function __construct(Installer $installer = null)
public function __construct(?Installer $installer = null)
{
$this->installer = $installer;
}
2 changes: 1 addition & 1 deletion src/Installer/Writer/PhpCsConfigWriter.php
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ final class PhpCsConfigWriter implements PhpCsConfigWriterInterface
{
public function writeConfigFile(?string $filename = null, bool $noDev = false, bool $noRisky = false): void
{
$filename = $filename ?: '.php-cs-fixer.dist.php';
$filename ??= '.php-cs-fixer.dist.php';
file_put_contents($filename, $this->createConfigSource($noDev, $noRisky));
}

8 changes: 8 additions & 0 deletions tests/AutoloadPathProviderTest.php
Original file line number Diff line number Diff line change
@@ -63,6 +63,14 @@ public function testGetPathsWithDevOff(): void
$this->assertSame($expected, $provider->getPaths());
}

public function testGetPathsWithDefault(): void
{
$provider = new AutoloadPathProvider();

$expected = ['src/', 'tests/'];
$this->assertSame($expected, $provider->getPaths());
}

public function testGetPathsWithWrongComposerJsonPath(): void
{
$provider = new AutoloadPathProvider(__DIR__ . '/composer.json');
4 changes: 3 additions & 1 deletion tests/Installer/Command/CreateConfigCommandTest.php
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ public function testSetConfigWriter(): void
/**
* @dataProvider executeProvider
*
* @param list<string> $args
*
* @throws \Exception
*/
public function testExecute(array $args, bool $noDev, bool $noRisky): void
@@ -54,7 +56,7 @@ public function testExecute(array $args, bool $noDev, bool $noRisky): void
}

/**
* @return array{string[], bool, bool}[]
* @return array{list<string>, bool, bool}[]
*/
public static function executeProvider(): array
{
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
* @psalm-suppress InternalClass
* @psalm-suppress InternalMethod
*/
abstract class AbstractRulesProviderTest extends TestCase
abstract class AbstractRulesProviderTestCase extends TestCase
{
abstract protected function shouldBeRisky(): bool;

@@ -33,7 +33,7 @@ public function testRuleAreRiskyAsExpected(string $ruleName): void
$this->assertSame(
$this->shouldBeRisky(),
$fixer->isRisky(),
sprintf('Fixer %s is %s as expected', $ruleName, $this->shouldBeRisky() ? 'risky' : 'NOT risky')
\sprintf('Fixer %s is %s as expected', $ruleName, $this->shouldBeRisky() ? 'risky' : 'NOT risky')
);
}

@@ -49,7 +49,7 @@ public function testRuleSetsAreRiskyAsExpected(string $ruleSetName): void
$this->assertSame(
$this->shouldBeRisky(),
$fixer->isRisky(),
sprintf('Ruleset %s includes %s rules, such as %s', $ruleSetName, $this->shouldBeRisky() ? 'risky' : 'NOT risky', $ruleName)
\sprintf('Ruleset %s includes %s rules, such as %s', $ruleSetName, $this->shouldBeRisky() ? 'risky' : 'NOT risky', $ruleName)
);
}
}
@@ -65,7 +65,9 @@ public function testRulesDoNotOverrideRuleSets(string $ruleName): void

$allowedOverrides = [
'binary_operator_spaces',
'no_extra_blank_lines',
'single_class_element_per_statement',
'trailing_comma_in_multiline', // see #72
];

if (\in_array($ruleName, $allowedOverrides)) {
@@ -82,16 +84,23 @@ public function testRulesDoNotOverrideRuleSets(string $ruleName): void
$this->assertConfigurationIsSameAsRuleSet($ruleSet, $ruleName);

if ($name === '@PER-CS2.0' && $this->isNotInPsr12($ruleName)) {
$this->markTestSkipped(sprintf('Rule %s is part of PER-CS but NOT of PSR-12, we can drop it only in the future', $ruleName));
$this->markTestSkipped(\sprintf('Rule %s is part of PER-CS but NOT of PSR-12, we can drop it only in the future', $ruleName));
}

$this->fail(sprintf('Rule %s is being overridden while already included in %s rule set, with the same config', $ruleName, $name));
$recentlyIncludedRules = [
'single_space_around_construct', // since 3.64.0 (#8171)
];
if (\in_array($ruleName, $recentlyIncludedRules, true)) {
$this->markTestSkipped(\sprintf('Rule %s was included in PER-CS ruleset recently, we can drop it only in the future', $ruleName));
}

$this->fail(\sprintf('Rule %s is being overridden while already included in %s rule set, with the same config', $ruleName, $name));
}
}

protected static function getRulesProvider(): RulesProviderInterface
{
throw new \LogicException(sprintf('Override %s to provide the proper concrete instance of %s', __METHOD__, RulesProviderInterface::class));
throw new \LogicException(\sprintf('Override %s to provide the proper concrete instance of %s', __METHOD__, RulesProviderInterface::class));
}

/**
@@ -128,22 +137,6 @@ protected function assertRulesAreAlphabeticallySorted(RulesProviderInterface $pr
$this->assertEquals($sortedRules, $rules, 'Rules are not alphabetically sorted');
}

protected function assertAllRulesAreRisky(bool $expected, RulesProviderInterface $rulesProvider): void
{
$rules = array_keys($rulesProvider->getRules());
$this->assertNotEmpty($rules, 'No rules from the provider!');

foreach ($rules as $ruleName) {
if (str_starts_with($ruleName, '@')) {
continue;
}

$fixer = $this->getFixerByName($ruleName);

$this->assertSame($expected, $fixer->isRisky(), 'Fixer is risky: ' . $ruleName);
}
}

private function assertConfigurationIsSameAsRuleSet(RuleSet $ruleSet, string $ruleName): void
{
$fixer = $this->getFixerByName($ruleName);
@@ -154,26 +147,27 @@ private function assertConfigurationIsSameAsRuleSet(RuleSet $ruleSet, string $ru
$rulesProvider = static::getRulesProvider();
$ruleConfiguration = $rulesProvider->getRules()[$ruleName];
$ruleSetConfiguration = $ruleSet->getRuleConfiguration($ruleName);
$defaultConfiguration = $fixer->getConfigurationDefinition()->resolve([]);
$defaultConfiguration = $this->getPerCsConfigurationFor($fixer)
?? $fixer->getConfigurationDefinition()->resolve([]);
$this->assertNotEmpty($defaultConfiguration, 'Empty default configuration?');

if ($ruleSetConfiguration === null) {
if ($ruleConfiguration === true) {
return;
}

$this->assertEquals($defaultConfiguration, $ruleConfiguration, sprintf(
$this->assertEquals($defaultConfiguration, $ruleConfiguration, \sprintf(
'Ruleset relies on default configuration for rule %s, but it is being overridden',
$ruleName
));
} elseif ($ruleConfiguration === true) {
$this->assertEquals($ruleSetConfiguration, $defaultConfiguration, sprintf(
$this->assertEquals($ruleSetConfiguration, $defaultConfiguration, \sprintf(
'Ruleset does not use the default config for rule %s, and it is being overridden with "true" in %s',
$ruleName,
\get_class($rulesProvider)
));
} else {
$this->assertEquals($ruleSetConfiguration, $ruleConfiguration, sprintf(
$this->assertEquals($ruleSetConfiguration, $ruleConfiguration, \sprintf(
'Rule %s has a different configuration from the one from ruleset',
$ruleName
));
@@ -255,4 +249,20 @@ private function isNotInPsr12(string $ruleName): bool

return ! $psr12->hasRule($ruleName);
}

private function getPerCsConfigurationFor(FixerInterface $fixer): ?array
{
/** @var RuleSet|null $perCs */
static $perCs;

$perCs ??= new RuleSet([
'@PER-CS2.0' => true,
]);

if (! $perCs->hasRule($fixer->getName())) {
return null;
}

return $perCs->getRuleConfiguration($fixer->getName());
}
}
2 changes: 1 addition & 1 deletion tests/Rules/DefaultRulesProviderTest.php
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

use const false;

class DefaultRulesProviderTest extends AbstractRulesProviderTest
class DefaultRulesProviderTest extends AbstractRulesProviderTestCase
{
protected static function getRulesProvider(): DefaultRulesProvider
{
2 changes: 1 addition & 1 deletion tests/Rules/RiskyRulesProviderTest.php
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

use Facile\CodingStandards\Rules\RiskyRulesProvider;

class RiskyRulesProviderTest extends AbstractRulesProviderTest
class RiskyRulesProviderTest extends AbstractRulesProviderTestCase
{
protected static function getRulesProvider(): RiskyRulesProvider
{
2 changes: 1 addition & 1 deletion tests/RulesMaintenance/DumperTest.php
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public function testGetUnlistedRulesDescription(): void
}

/**
* This test may break a lot when new rules are introducted in PHP-CS-Fixer
* This test may break a lot when new rules are introduced in PHP-CS-Fixer
* An easy fix is to add them to {@see RulesList::getToBeDiscussedRules()}.
*/
public function testNoRuleIsUnlisted(): void
6 changes: 6 additions & 0 deletions tests/RulesMaintenance/RulesList.php
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ public static function getToBeImplementedRules(): array
{
return [
'get_class_to_class_keyword', // already active, shut off here due to PHP 7.4 support
'php_unit_assert_new_names', // requires PHPUnit 9.1
];
}

@@ -63,11 +64,13 @@ public static function getToBeDiscussedRules(): array
'heredoc_closing_marker', // possibly undesired?
'multiline_string_to_heredoc', // possibly undesired?
'multiline_whitespace_before_semicolons', // with new_line_for_chained_calls
'ordered_attributes',
'ordered_types',
'php_unit_method_casing',
'php_unit_test_case_static_method_calls',
'self_static_accessor',
'single_line_comment_style',
'string_implicit_backslashes',
];
}

@@ -101,6 +104,7 @@ public static function getUndesirableRules(): array
'php_unit_test_class_requires_covers',
'phpdoc_add_missing_param_annotation',
'phpdoc_line_span',
'phpdoc_list_type',
'phpdoc_order_by_value',
'phpdoc_to_comment', // disabled in 0.5.3
'phpdoc_types_order',
@@ -141,6 +145,7 @@ public static function getUnapplicableRules(): array
public static function getBestHandledWithRectorRules(): array
{
return [
'php_unit_attributes',
'php_unit_no_expectation_annotation',
'regular_callable_call',
'simplified_if_return',
@@ -174,6 +179,7 @@ public static function getTooRiskyRules(): array
'php_unit_data_provider_name',
'php_unit_strict',
'php_unit_test_annotation',
'phpdoc_array_type',
'phpdoc_readonly_class_comment_to_keyword',
'phpdoc_return_self_reference',
'phpdoc_to_param_type',