Skip to content

Commit

Permalink
Add MagicMethodCasingFixer to check correct magic method casing
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 21, 2024
1 parent b660c08 commit 0f8e541
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -158,4 +160,10 @@ but should be heredoc instead';
// NullableTypeDeclarationForDefaultNullValueFixer
string $anotherNullableValue = null,
): void {}

// MagicMethodCasingFixer, OrderedClassElementsFixer
public function __ToString(): string
{
return '';
}
}

0 comments on commit 0f8e541

Please sign in to comment.