Skip to content

Commit

Permalink
Skip date time on naming, as custom standard (#3278)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 13, 2023
1 parent 9a2bcbf commit bea3bc6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
use PHPStan\Type\ObjectType;
use Rector\Naming\Naming\PropertyNaming;
use Rector\Naming\ValueObject\ExpectedName;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\StaticTypeMapper\StaticTypeMapper;

final class MatchParamTypeExpectedNameResolver
{
public function __construct(
private readonly StaticTypeMapper $staticTypeMapper,
private readonly PropertyNaming $propertyNaming,
private readonly NodeNameResolver $nodeNameResolver,
) {
}

Expand All @@ -31,9 +29,7 @@ public function resolve(Param $param): ?string

// skip date time + date time interface, as should be kept
if ($staticType instanceof ObjectType && $staticType->isInstanceOf('DateTimeInterface')->yes()) {
if ($this->nodeNameResolver->isName($param, '*At')) {
return null;
}
return null;
}

$expectedName = $this->propertyNaming->getExpectedNameFromType($staticType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ declare(strict_types=1);

namespace Rector\Core\Tests\Issues\IssueConstructorPromotionRename\Fixture;

use Rector\Core\Tests\Issues\IssueConstructorPromotionRename\Source\PromotedPropertyObject;

final class Fixture
{
private $a;
public function __construct(\DateTimeInterface $a)

public function __construct(PromotedPropertyObject $a)
{
$this->a = $a;
dump($a);
dump($a->format('Y-m-d'));
dump($a->someCall('Y-m-d'));
}
}

Expand All @@ -23,12 +26,14 @@ declare(strict_types=1);

namespace Rector\Core\Tests\Issues\IssueConstructorPromotionRename\Fixture;

use Rector\Core\Tests\Issues\IssueConstructorPromotionRename\Source\PromotedPropertyObject;

final class Fixture
{
public function __construct(private \DateTimeInterface $dateTime)
public function __construct(private PromotedPropertyObject $promotedPropertyObject)
{
dump($dateTime);
dump($dateTime->format('Y-m-d'));
dump($promotedPropertyObject);
dump($promotedPropertyObject->someCall('Y-m-d'));
}
}

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

declare(strict_types=1);

namespace Rector\Core\Tests\Issues\IssueConstructorPromotionRename\Source;

final class PromotedPropertyObject
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ declare(strict_types=1);

namespace Rector\Core\Tests\Issues\IssueCreatePublicPropertyOnRename\Fixture;

final class DemoFile
use Rector\Core\Tests\Issues\IssueCreatePublicPropertyOnRename\Source\SomePropertyObject;

final class Fixture
{
public function __construct(private \DateTimeImmutable $date)
public function __construct(private SomePropertyObject $date)
{
}

Expand All @@ -23,15 +25,17 @@ declare(strict_types=1);

namespace Rector\Core\Tests\Issues\IssueCreatePublicPropertyOnRename\Fixture;

final class DemoFile
use Rector\Core\Tests\Issues\IssueCreatePublicPropertyOnRename\Source\SomePropertyObject;

final class Fixture
{
public function __construct(private \DateTimeImmutable $dateTimeImmutable)
public function __construct(private SomePropertyObject $somePropertyObject)
{
}

public function run(): string
{
return $this->dateTimeImmutable->format('l, F j, Y');
return $this->somePropertyObject->format('l, F j, Y');
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\Issues\IssueCreatePublicPropertyOnRename\Source;

final class SomePropertyObject
{

}

0 comments on commit bea3bc6

Please sign in to comment.