Skip to content

Commit 8c778e8

Browse files
committed
Merge branch 'feature/file-getimplementedinterfacenames-add-enum-support' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 1c82e07 + daff272 commit 8c778e8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/Files/File.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,11 +2768,11 @@ public function findExtendedClassName($stackPtr)
27682768

27692769

27702770
/**
2771-
* Returns the names of the interfaces that the specified class implements.
2771+
* Returns the names of the interfaces that the specified class or enum implements.
27722772
*
27732773
* Returns FALSE on error or if there are no implemented interface names.
27742774
*
2775-
* @param int $stackPtr The stack position of the class.
2775+
* @param int $stackPtr The stack position of the class or enum token.
27762776
*
27772777
* @return array|false
27782778
*/
@@ -2785,6 +2785,7 @@ public function findImplementedInterfaceNames($stackPtr)
27852785

27862786
if ($this->tokens[$stackPtr]['code'] !== T_CLASS
27872787
&& $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2788+
&& $this->tokens[$stackPtr]['code'] !== T_ENUM
27882789
) {
27892790
return false;
27902791
}

tests/Core/File/FindImplementedInterfaceNamesTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,12 @@ class testFECNClassThatExtendsAndImplements extends testFECNClass implements Int
2424

2525
/* testClassThatImplementsAndExtends */
2626
class testFECNClassThatImplementsAndExtends implements \InterfaceA, InterfaceB extends testFECNClass {}
27+
28+
/* testBackedEnumWithoutImplements */
29+
enum Suit:string {}
30+
31+
/* testEnumImplements */
32+
enum Suit implements Colorful {}
33+
34+
/* testBackedEnumImplements */
35+
enum Suit: string implements Colorful, \Deck {}

tests/Core/File/FindImplementedInterfaceNamesTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FindImplementedInterfaceNamesTest extends AbstractMethodUnitTest
2727
*/
2828
public function testFindImplementedInterfaceNames($identifier, $expected)
2929
{
30-
$OOToken = $this->getTargetToken($identifier, [T_CLASS, T_ANON_CLASS, T_INTERFACE]);
30+
$OOToken = $this->getTargetToken($identifier, [T_CLASS, T_ANON_CLASS, T_INTERFACE, T_ENUM]);
3131
$result = self::$phpcsFile->findImplementedInterfaceNames($OOToken);
3232
$this->assertSame($expected, $result);
3333

@@ -81,6 +81,21 @@ public function dataImplementedInterface()
8181
'InterfaceB',
8282
],
8383
],
84+
[
85+
'/* testBackedEnumWithoutImplements */',
86+
false,
87+
],
88+
[
89+
'/* testEnumImplements */',
90+
['Colorful'],
91+
],
92+
[
93+
'/* testBackedEnumImplements */',
94+
[
95+
'Colorful',
96+
'\Deck',
97+
],
98+
],
8499
];
85100

86101
}//end dataImplementedInterface()

0 commit comments

Comments
 (0)