Skip to content

Commit

Permalink
Squiz/ScopeKeywordSpacing: check spaces after abstract and final
Browse files Browse the repository at this point in the history
…keyword (#604)

The correct spacing after the `final` and `abstract` modifier keywords was not checked by this sniff, while these are typical modifier keywords which should be checked.

Includes tests.
  • Loading branch information
klausi authored and jrfnl committed Jan 23, 2025
1 parent b8e2ab3 commit d13884b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ScopeKeywordSpacingSniff implements Sniff
*/
public function register()
{
$register = Tokens::$scopeModifiers;
$register[] = T_STATIC;
$register = Tokens::$methodPrefixes;
$register[] = T_READONLY;
return $register;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,30 @@ readonly class ReadonlyClassTest {}
// PHP 8.3 readonly anonymous classes.
$anon = new readonly class {};
$anon = new readonly class {};

class FinalTest {
final public static function create(ContainerInterface $container) {}
}

final class FinalTest2 {
}

final
readonly class FinalTest3 {}

class FinalTest4 {
final const X = "foo";
final public const Y = "bar";
}

abstract class AbstractTest {
abstract public function foo();
}

final class FinalSpacingCorrect {
public final const SPACING_CORRECT = true;
}

abstract class AbstractSpacingCorrect {
public abstract function spacingCorrect() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,29 @@ readonly class ReadonlyClassTest {}
// PHP 8.3 readonly anonymous classes.
$anon = new readonly class {};
$anon = new readonly class {};

class FinalTest {
final public static function create(ContainerInterface $container) {}
}

final class FinalTest2 {
}

final readonly class FinalTest3 {}

class FinalTest4 {
final const X = "foo";
final public const Y = "bar";
}

abstract class AbstractTest {
abstract public function foo();
}

final class FinalSpacingCorrect {
public final const SPACING_CORRECT = true;
}

abstract class AbstractSpacingCorrect {
public abstract function spacingCorrect() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public function getErrorList($testFile='')
140 => 3,
145 => 1,
149 => 1,
152 => 1,
155 => 1,
158 => 1,
162 => 1,
163 => 1,
166 => 1,
167 => 1,
];

case 'ScopeKeywordSpacingUnitTest.3.inc':
Expand Down

0 comments on commit d13884b

Please sign in to comment.