Skip to content
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: 3 additions & 2 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2765,11 +2765,11 @@ public function findExtendedClassName($stackPtr)


/**
* Returns the names of the interfaces that the specified class implements.
* Returns the names of the interfaces that the specified class or enum implements.
*
* Returns FALSE on error or if there are no implemented interface names.
*
* @param int $stackPtr The stack position of the class.
* @param int $stackPtr The stack position of the class or enum token.
*
* @return array|false
*/
Expand All @@ -2782,6 +2782,7 @@ public function findImplementedInterfaceNames($stackPtr)

if ($this->tokens[$stackPtr]['code'] !== T_CLASS
&& $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
&& $this->tokens[$stackPtr]['code'] !== T_ENUM
) {
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Core/File/FindImplementedInterfaceNamesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ class testFECNClassThatExtendsAndImplements extends testFECNClass implements Int

/* testClassThatImplementsAndExtends */
class testFECNClassThatImplementsAndExtends implements \InterfaceA, InterfaceB extends testFECNClass {}

/* testBackedEnumWithoutImplements */
enum Suit:string {}

/* testEnumImplements */
enum Suit implements Colorful {}

/* testBackedEnumImplements */
enum Suit: string implements Colorful, \Deck {}
17 changes: 16 additions & 1 deletion tests/Core/File/FindImplementedInterfaceNamesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FindImplementedInterfaceNamesTest extends AbstractMethodUnitTest
*/
public function testFindImplementedInterfaceNames($identifier, $expected)
{
$OOToken = $this->getTargetToken($identifier, [T_CLASS, T_ANON_CLASS, T_INTERFACE]);
$OOToken = $this->getTargetToken($identifier, [T_CLASS, T_ANON_CLASS, T_INTERFACE, T_ENUM]);
$result = self::$phpcsFile->findImplementedInterfaceNames($OOToken);
$this->assertSame($expected, $result);

Expand Down Expand Up @@ -81,6 +81,21 @@ public function dataImplementedInterface()
'InterfaceB',
],
],
[
'/* testBackedEnumWithoutImplements */',
false,
],
[
'/* testEnumImplements */',
['Colorful'],
],
[
'/* testBackedEnumImplements */',
[
'Colorful',
'\Deck',
],
],
];

}//end dataImplementedInterface()
Expand Down