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

ObjectDeclarations::getClassProperties(): allow for abstract final #252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
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,
],
],
];
}
}