Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#112 - class keyword fixer #128

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Fixers/ClassKeywordFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Tokens;
use ReflectionClass;
use SplFileInfo;

final class ClassKeywordFixer implements FixerInterface
Expand Down Expand Up @@ -72,7 +73,7 @@ public function getName(): string

public function getPriority(): int
{
return 0;
krzysztofrewak marked this conversation as resolved.
Show resolved Hide resolved
return 33;
}

public function supports(SplFileInfo $file): bool
Expand All @@ -82,10 +83,10 @@ public function supports(SplFileInfo $file): bool

private function exists(string $name): bool
{
if (class_exists($name) || interface_exists($name) || trait_exists($name)) {
$rc = new \ReflectionClass($name);
if (class_exists($name) || interface_exists($name) || trait_exists($name) || enum_exists($name)) {
$reflection = new ReflectionClass($name);

return $rc->getName() === $name;
return $reflection->getName() === $name;
}

return false;
Expand Down
1 change: 0 additions & 1 deletion tests/codestyle/CommonRulesetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public static function providePhp80Fixtures(): array
["noMultilineWhitespaceAroundDoubleArrow"],
["compactArray"],
["classesImport"],
["namedParameters"],
];
}

Expand Down
12 changes: 7 additions & 5 deletions tests/fixtures/classesImport/expected.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
declare(strict_types=1);

use Blumilk\Codestyle\Configuration\Defaults\CommonRules;
use Blumilk\Codestyle\Configuration\Defaults\Paths;
use PhpCsFixer\Tokenizer\Tokens;

class TestException extends Exception
{
protected string $var = "Error";
protected string $class = \Error::class;
protected string $class = Error::class;
protected string $laravel = "LaravelPaths";
protected string $bar = \PhpCsFixer\Tokenizer\Tokens::class;
protected string $foo = \PhpCsFixer\Tokenizer\Tokens::class;
protected string $bar = Tokens::class;
protected string $foo = Tokens::class;
protected string $faz = "\Tokens";

public function rules(CommonRules $rules): void
Expand All @@ -20,8 +22,8 @@ public function rules(CommonRules $rules): void

public function test(): void
{
$foo = \Blumilk\Codestyle\Configuration\Defaults\Paths::class;
$baz = \Exception::class;
$foo = Paths::class;
$baz = Exception::class;
$fuz = "Exception";
}
}
Loading