Skip to content

Commit 0f8e541

Browse files
committed
Add MagicMethodCasingFixer to check correct magic method casing
1 parent b660c08 commit 0f8e541

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

ecs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer;
5151
use PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer;
5252
use PhpCsFixer\Fixer\Casing\ClassReferenceNameCasingFixer;
53+
use PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer;
5354
use PhpCsFixer\Fixer\Casing\MagicMethodCasingFixer;
5455
use PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer;
5556
use PhpCsFixer\Fixer\Casing\NativeTypeDeclarationCasingFixer;
@@ -258,6 +259,8 @@
258259
PsrAutoloadingFixer::class,
259260
// When referencing an internal class it must be written using the correct casing.
260261
ClassReferenceNameCasingFixer::class,
262+
// Magic constants should be referred to using the correct casing.
263+
MagicConstantCasingFixer::class,
261264
// Magic method definitions and calls must be using the correct casing
262265
MagicMethodCasingFixer::class,
263266
// Function defined by PHP should be called using the correct casing

tests/Integration/Fixtures/Basic.correct.php.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
1515

1616
protected int $myProperty = 666; // OrderedClassElementsFixer
1717

18+
// MagicMethodCasingFixer, OrderedClassElementsFixer
19+
public function __toString(): string
20+
{
21+
return '';
22+
}
23+
1824
public function isEqual($a, ?string $b): ?bool // VisibilityRequiredFixer, CompactNullableTypeDeclarationFixer
1925
{
2026
// TrimArraySpacesFixer
@@ -44,6 +50,8 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
4450

4551
public function fooBar(mixed $foo): mixed // FunctionDeclarationFixer
4652
{
53+
// MagicConstantCasingFixer
54+
$magicConstant = __DIR__;
4755
$value = 5;
4856
// FunctionDeclarationFixer
4957
$function = function ($foo) use ($value) {

tests/Integration/Fixtures/Basic.wrong.php.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Basic extends \Some\Other\Namespace\AbstractBasic implements \Lmc\CodingSt
3636

3737
public function fooBar ( mixed $foo ): mixed // FunctionDeclarationFixer
3838
{
39+
// MagicConstantCasingFixer
40+
$magicConstant = __dir__;
3941
$value = 5;
4042
// FunctionDeclarationFixer
4143
$function = function($foo)use($value) {
@@ -158,4 +160,10 @@ but should be heredoc instead';
158160
// NullableTypeDeclarationForDefaultNullValueFixer
159161
string $anotherNullableValue = null,
160162
): void {}
163+
164+
// MagicMethodCasingFixer, OrderedClassElementsFixer
165+
public function __ToString(): string
166+
{
167+
return '';
168+
}
161169
}

0 commit comments

Comments
 (0)