Skip to content

Commit 3edca66

Browse files
authoredMar 28, 2025
Skip DateTime from property type to property renaming to keep code readable (#6812)
1 parent e7b063f commit 3edca66

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed
 

‎rules-tests/Naming/Rector/Class_/RenamePropertyToMatchTypeRector/Fixture/keep_date_time.php.inc

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ namespace Rector\Tests\Naming\Rector\Class_\RenamePropertyToMatchTypeRector\Fixt
44

55
final class KeepDateTime
66
{
7-
public function __construct(
8-
private \DateTimeInterface $cratedAt,
7+
private ?DateTime $timestamp = null;
8+
9+
public function setValue(
10+
\DateTime $timestamp,
911
) {
12+
$this->timestamp = $timestamp;
1013
}
1114
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\Naming\Rector\Class_\RenamePropertyToMatchTypeRector\Fixture;
4+
5+
final class KeepDateTimeInterface
6+
{
7+
public function __construct(
8+
private \DateTimeInterface $cratedAt,
9+
) {
10+
}
11+
}

‎rules/DeadCode/Rector/FuncCall/RemoveFilterVarOnExactTypeRector.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public function refactor(Node $node): ?Node
8585
if (in_array(
8686
$constantFilterName,
8787
['FILTER_VALIDATE_BOOLEAN', 'FILTER_VALIDATE_BOOL']
88-
) && $valueType->isBoolean()->yes()) {
88+
) && $valueType->isBoolean()
89+
->yes()) {
8990
return $firstArgValue;
9091
}
9192

‎rules/Naming/Rector/Class_/RenamePropertyToMatchTypeRector.php

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ private function skipDateTimeOrMockObjectPropertyType(Property $property): bool
148148
if ($this->isName($property->type, ClassName::MOCK_OBJECT)) {
149149
return true;
150150
}
151-
152151
return $this->isName($property->type, ClassName::DATE_TIME);
153152
}
154153
}

‎rules/Naming/RenameGuard/PropertyRenameGuard.php

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public function shouldSkip(PropertyRename $propertyRename): bool
3232
return true;
3333
}
3434

35+
// skip date times, as often custom named and using "dateTime" does not bring any value to code
36+
if ($propertyRename->getExpectedName() === 'dateTime') {
37+
return true;
38+
}
39+
3540
if ($this->dateTimeAtNamingConventionGuard->isConflicting($propertyRename)) {
3641
return true;
3742
}

‎src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Rector\NodeTypeResolver\PHPStan\Scope;
66

7-
use PHPStan\Analyser\UndefinedVariableException;
87
use Error;
98
use PhpParser\Node;
109
use PhpParser\Node\Arg;
@@ -88,6 +87,7 @@
8887
use PHPStan\Analyser\MutatingScope;
8988
use PHPStan\Analyser\NodeScopeResolver;
9089
use PHPStan\Analyser\ScopeContext;
90+
use PHPStan\Analyser\UndefinedVariableException;
9191
use PHPStan\Node\FunctionCallableNode;
9292
use PHPStan\Node\InstantiationCallableNode;
9393
use PHPStan\Node\MethodCallableNode;

0 commit comments

Comments
 (0)