Skip to content

Commit

Permalink
Merge pull request #252 from PHPCSStandards/feature/objectdeclaration…
Browse files Browse the repository at this point in the history
…s-getclassproperties-allow-for-final

ObjectDeclarations::getClassProperties(): allow for `abstract final`
  • Loading branch information
jrfnl authored May 13, 2021
2 parents af11185 + 513a078 commit 7a4fab4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
5 changes: 2 additions & 3 deletions PHPCSUtils/Utils/ObjectDeclarations.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public static function getName(File $phpcsFile, $stackPtr)
* - Bugs fixed:
* - Handling of PHPCS annotations.
* - Handling of unorthodox docblock placement.
* - A class cannot both be abstract as well as final, so this utility should not allow for that.
* - Defensive coding against incorrect calls to this method.
*
* @see \PHP_CodeSniffer\Files\File::getClassProperties() Original source.
Expand Down Expand Up @@ -203,11 +202,11 @@ public static function getClassProperties(File $phpcsFile, $stackPtr)
switch ($tokens[$i]['code']) {
case \T_ABSTRACT:
$properties['is_abstract'] = true;
break 2;
break;

case \T_FINAL:
$properties['is_final'] = true;
break 2;
break;
}
}

Expand Down
7 changes: 7 additions & 0 deletions Tests/BackCompat/BCFile/GetClassPropertiesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ abstract
* @phpcs:disable Standard.Cat.SniffName -- Just because.
*/
class ClassWithDocblock {}

/* testParseErrorAbstractFinal */
final /* comment */

abstract // Intentional parse error, class cannot both be final and abstract.

class AbstractFinal {}
7 changes: 7 additions & 0 deletions Tests/BackCompat/BCFile/GetClassPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ public function dataGetClassProperties()
'is_final' => false,
],
],
'abstract-final-parse-error' => [
'/* testParseErrorAbstractFinal */',
[
'is_abstract' => true,
'is_final' => true,
],
],
];
}
}
7 changes: 0 additions & 7 deletions Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,3 @@ final
* @phpcs:disable Standard.Cat.SniffName -- Just because.
*/
class ClassWithPropertyBeforeDocblock {}

/* testParseErrorAbstractFinal */
final /* comment */

abstract // Intentional parse error, class cannot both be final and abstract.

class AbstractFinal {}
7 changes: 0 additions & 7 deletions Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ public function dataGetClassProperties()
'is_final' => true,
],
],
'abstract-final-parse-error' => [
'/* testParseErrorAbstractFinal */',
[
'is_abstract' => true,
'is_final' => false,
],
],
];
}
}

0 comments on commit 7a4fab4

Please sign in to comment.