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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\Source\SimpleStringable;

final class SkipStringableObject extends TestCase
{
public function test()
{
$this->assertEquals('value', new SimpleStringable());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\Source;

use Stringable;

final class SimpleStringable implements Stringable
{
public function __toString()
{
return 'value';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
Expand Down Expand Up @@ -49,7 +50,7 @@ final class AssertEqualsToSameRector extends AbstractRector

public function __construct(
private readonly IdentifierManipulator $identifierManipulator,
private readonly TestsNodeAnalyzer $testsNodeAnalyzer
private readonly TestsNodeAnalyzer $testsNodeAnalyzer,
) {
}

Expand Down Expand Up @@ -113,6 +114,13 @@ public function refactor(Node $node): ?Node
if ($firstArgType instanceof FloatType && ($secondArgType instanceof IntegerType || $secondArgType instanceof MixedType)) {
return null;
}

if ($firstArgType instanceof StringType && $secondArgType instanceof ObjectType && $this->isObjectType(
$args[1]->value,
new ObjectType('Stringable')
)) {
return null;
}
}

$hasChanged = $this->identifierManipulator->renameNodeWithMap($node, self::RENAME_METHODS_MAP);
Expand Down
Loading