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
11 changes: 8 additions & 3 deletions BigBite/Sniffs/Classes/StringableSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ public function process( File $phpcsFile, $stackPtr ) {
$interfaces = ObjectDeclarations::findImplementedInterfaceNames( $phpcsFile, $classDecl );

// we're good - class containing __toString implements the interface.
if ( is_array( $interfaces ) && in_array( 'Stringable', $interfaces, true ) ) {
if (
is_array( $interfaces ) && (
in_array( '\\Stringable', $interfaces, true ) ||
in_array( 'Stringable', $interfaces, true )
)
) {
return;
}

Expand All @@ -88,7 +93,7 @@ public function process( File $phpcsFile, $stackPtr ) {
}

$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->addContent( $prevToken, ' implements Stringable' );
$phpcsFile->fixer->addContent( $prevToken, ' implements \\Stringable' );
$phpcsFile->fixer->endChangeset();

return;
Expand All @@ -101,7 +106,7 @@ public function process( File $phpcsFile, $stackPtr ) {
}

$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->addContentBefore( $endOfLine, ' implements Stringable' );
$phpcsFile->fixer->addContentBefore( $endOfLine, ' implements \\Stringable' );
$phpcsFile->fixer->endChangeset();
}
}
2 changes: 1 addition & 1 deletion BigBite/Tests/Classes/StringableUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class DoesNotImplementToStringMagicMethod {
}

class CorrectlyImplementsStringable implements Stringable {
class CorrectlyImplementsStringable implements \Stringable {
public function __toString(): string {
return __CLASS__;
}
Expand Down
8 changes: 4 additions & 4 deletions BigBite/Tests/Classes/StringableUnitTest.1.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
class DoesNotImplementToStringMagicMethod {
}

class CorrectlyImplementsStringable implements Stringable {
class CorrectlyImplementsStringable implements \Stringable {
public function __toString(): string {
return __CLASS__;
}
}

class IncorrectWithWhitespace implements Stringable {
class IncorrectWithWhitespace implements \Stringable {
public function __toString(): string {
return __CLASS__;
}
}

class IncorrectWithNoWhitespace implements Stringable{
class IncorrectWithNoWhitespace implements \Stringable{
public function __toString(): string {
return __CLASS__;
}
}

class IncorrectWithNewline implements Stringable
class IncorrectWithNewline implements \Stringable
{
public function __toString(): string {
return __CLASS__;
Expand Down