From 0f8e5419a1e11c4f2e7c5a65db930f962188f79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Tue, 21 May 2024 14:17:05 +0200 Subject: [PATCH] Add MagicMethodCasingFixer to check correct magic method casing --- ecs.php | 3 +++ tests/Integration/Fixtures/Basic.correct.php.inc | 8 ++++++++ tests/Integration/Fixtures/Basic.wrong.php.inc | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/ecs.php b/ecs.php index 07aef91..4f7784f 100644 --- a/ecs.php +++ b/ecs.php @@ -50,6 +50,7 @@ use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer; use PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer; use PhpCsFixer\Fixer\Casing\ClassReferenceNameCasingFixer; +use PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer; use PhpCsFixer\Fixer\Casing\MagicMethodCasingFixer; use PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer; use PhpCsFixer\Fixer\Casing\NativeTypeDeclarationCasingFixer; @@ -258,6 +259,8 @@ PsrAutoloadingFixer::class, // When referencing an internal class it must be written using the correct casing. ClassReferenceNameCasingFixer::class, + // Magic constants should be referred to using the correct casing. + MagicConstantCasingFixer::class, // Magic method definitions and calls must be using the correct casing MagicMethodCasingFixer::class, // Function defined by PHP should be called using the correct casing diff --git a/tests/Integration/Fixtures/Basic.correct.php.inc b/tests/Integration/Fixtures/Basic.correct.php.inc index d43a1d3..b2e6454 100644 --- a/tests/Integration/Fixtures/Basic.correct.php.inc +++ b/tests/Integration/Fixtures/Basic.correct.php.inc @@ -15,6 +15,12 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully protected int $myProperty = 666; // OrderedClassElementsFixer + // MagicMethodCasingFixer, OrderedClassElementsFixer + public function __toString(): string + { + return ''; + } + public function isEqual($a, ?string $b): ?bool // VisibilityRequiredFixer, CompactNullableTypeDeclarationFixer { // TrimArraySpacesFixer @@ -44,6 +50,8 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully public function fooBar(mixed $foo): mixed // FunctionDeclarationFixer { + // MagicConstantCasingFixer + $magicConstant = __DIR__; $value = 5; // FunctionDeclarationFixer $function = function ($foo) use ($value) { diff --git a/tests/Integration/Fixtures/Basic.wrong.php.inc b/tests/Integration/Fixtures/Basic.wrong.php.inc index c190038..15bd67a 100644 --- a/tests/Integration/Fixtures/Basic.wrong.php.inc +++ b/tests/Integration/Fixtures/Basic.wrong.php.inc @@ -36,6 +36,8 @@ class Basic extends \Some\Other\Namespace\AbstractBasic implements \Lmc\CodingSt public function fooBar ( mixed $foo ): mixed // FunctionDeclarationFixer { + // MagicConstantCasingFixer + $magicConstant = __dir__; $value = 5; // FunctionDeclarationFixer $function = function($foo)use($value) { @@ -158,4 +160,10 @@ but should be heredoc instead'; // NullableTypeDeclarationForDefaultNullValueFixer string $anotherNullableValue = null, ): void {} + + // MagicMethodCasingFixer, OrderedClassElementsFixer + public function __ToString(): string + { + return ''; + } }