Skip to content

Commit

Permalink
[Naming] Fix add fixture RenameVariableToMatchMethodCallReturnTypeRec…
Browse files Browse the repository at this point in the history
…tor for date time assign (#3277)
  • Loading branch information
TomasVotruba committed Jan 13, 2023
1 parent b91f35f commit 9a2bcbf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\FixturePhp74;
namespace Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Fixture;

use Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Source\SameNameMethod;

Expand All @@ -16,7 +16,7 @@ final class SomeArrowFunction
-----
<?php

namespace Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\FixturePhp74;
namespace Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Fixture;

use Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Source\SameNameMethod;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Fixture;

use Nette\Utils\DateTime;
use Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Source\SameNameMethod;

final class SkipAssignDateTime
{
public function run(SameNameMethod $sameNameMethod)
{
$createdAt = DateTime::from('now');
}
}
5 changes: 5 additions & 0 deletions rules/Naming/Naming/ExpectedNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public function resolveForCall(MethodCall | StaticCall | FuncCall $expr): ?strin
return null;
}

if ($returnedType instanceof ObjectType && $returnedType->isInstanceOf('DateTimeInterface')->yes()) {
// skip date time, as custom naming
return null;
}

$expectedName = $this->propertyNaming->getExpectedNameFromType($returnedType);
if ($expectedName !== null) {
return $expectedName->getName();
Expand Down

0 comments on commit 9a2bcbf

Please sign in to comment.