Skip to content

Commit

Permalink
Cleanup solution and add note about why this hack has been introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
erickskrauch committed Jun 21, 2024
1 parent 17b15ff commit 65c94ea
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
23 changes: 23 additions & 0 deletions src/Fixer/ConfigurableFixerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace ErickSkrauch\PhpCsFixer\Fixer;

use PhpCsFixer\AbstractFixer;

// PHP-CS-Fixer 3.59.3 has changed implementation of the AbstractFixer by removing method `configure` from it
// and introducing a separate trait \PhpCsFixer\Fixer\ConfigurableFixerTrait with this method inside.
// To mitigate these changes and maintain compatibility with older versions of PHP-CS-Fixer, this solution was created.
//
// Commit: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/commit/064efa1f#diff-e1fb45756cd1d53b6d67072d8a026692c07af55617018229b0bf4ab6c22e3e53L105
// See https://github.com/erickskrauch/php-cs-fixer-custom-fixers/issues/12
if (method_exists(AbstractFixer::class, 'configure')) {

Check failure on line 14 in src/Fixer/ConfigurableFixerTrait.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 with lint

Call to function method_exists() with 'PhpCsFixer\\AbstractFixer' and 'configure' will always evaluate to true.
trait ConfigurableFixerTrait {

}
} else {
trait ConfigurableFixerTrait {
use \PhpCsFixer\Fixer\ConfigurableFixerTrait;

}
}
5 changes: 2 additions & 3 deletions src/Fixer/FunctionNotation/AlignMultilineParametersFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ErickSkrauch\PhpCsFixer\Fixer\FunctionNotation;

use ErickSkrauch\PhpCsFixer\Fixer\AbstractFixer;
use ErickSkrauch\PhpCsFixer\Legacy\LegacyConfigurableFixerTrait;
use ErickSkrauch\PhpCsFixer\Fixer\ConfigurableFixerTrait;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
Expand Down Expand Up @@ -35,8 +35,7 @@
* }
*/
final class AlignMultilineParametersFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface {

use LegacyConfigurableFixerTrait;
use ConfigurableFixerTrait;

/**
* @internal
Expand Down
5 changes: 2 additions & 3 deletions src/Fixer/Whitespace/BlankLineAroundClassBodyFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ErickSkrauch\PhpCsFixer\Fixer\Whitespace;

use ErickSkrauch\PhpCsFixer\Fixer\AbstractFixer;
use ErickSkrauch\PhpCsFixer\Legacy\LegacyConfigurableFixerTrait;
use ErickSkrauch\PhpCsFixer\Fixer\ConfigurableFixerTrait;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
Expand Down Expand Up @@ -32,8 +32,7 @@
* } $configuration
*/
final class BlankLineAroundClassBodyFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface {

use LegacyConfigurableFixerTrait;
use ConfigurableFixerTrait;

/**
* @internal
Expand Down
5 changes: 2 additions & 3 deletions src/Fixer/Whitespace/MultilineIfStatementBracesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ErickSkrauch\PhpCsFixer\Fixer\Whitespace;

use ErickSkrauch\PhpCsFixer\Fixer\AbstractFixer;
use ErickSkrauch\PhpCsFixer\Legacy\LegacyConfigurableFixerTrait;
use ErickSkrauch\PhpCsFixer\Fixer\ConfigurableFixerTrait;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
Expand All @@ -24,8 +24,7 @@
* } $configuration
*/
final class MultilineIfStatementBracesFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface {

use LegacyConfigurableFixerTrait;
use ConfigurableFixerTrait;

/**
* @internal
Expand Down
16 changes: 0 additions & 16 deletions src/Legacy/LegacyConfigurableFixerTrait.php

This file was deleted.

0 comments on commit 65c94ea

Please sign in to comment.