Skip to content

Commit

Permalink
Fixes #12. Add trait for compatibility with PHP-CS-Fixer 3.59.3 (#14)
Browse files Browse the repository at this point in the history
* Add trait for compatibility with 3.59.2 and 3.59.3

* Cleanup solution and add note about why this hack has been introduced

* Suppress PHPStan for method_exists call

---------

Co-authored-by: ErickSkrauch <[email protected]>
  • Loading branch information
alamirault and erickskrauch authored Jun 21, 2024
1 parent 1c1c04b commit 91e7c98
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Fixer/ConfigurableFixerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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
// @phpstan-ignore-next-line sometimes it exists, sometime it's not ;)
if (method_exists(AbstractFixer::class, 'configure')) {
trait ConfigurableFixerTrait {

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

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

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

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

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

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

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

/**
* @internal
Expand Down

0 comments on commit 91e7c98

Please sign in to comment.