File tree Expand file tree Collapse file tree
rules-tests/Naming/Rector/Class_/RenamePropertyToMatchTypeRector/Fixture Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ namespace Rector\Tests\Naming\Rector\Class_\RenamePropertyToMatchTypeRector\Fixt
44
55final class KeepDateTime
66{
7- private ?DateTime $ timestamp = null ;
7+ private ?\ DateTime $ timestamp = null ;
88
99 public function setValue (
1010 \DateTime $ timestamp ,
Original file line number Diff line number Diff line change 66
77use PhpParser \Node ;
88use PhpParser \Node \Param ;
9- use PHPStan \Type \ObjectType ;
109use Rector \Naming \Naming \PropertyNaming ;
1110use Rector \Naming \ValueObject \ExpectedName ;
12- use Rector \NodeTypeResolver \NodeTypeResolver ;
1311use Rector \StaticTypeMapper \StaticTypeMapper ;
1412
1513final readonly class MatchParamTypeExpectedNameResolver
1614{
1715 public function __construct (
1816 private StaticTypeMapper $ staticTypeMapper ,
1917 private PropertyNaming $ propertyNaming ,
20- private NodeTypeResolver $ nodeTypeResolver ,
2118 ) {
2219 }
2320
@@ -28,12 +25,6 @@ public function resolve(Param $param): ?string
2825 return null ;
2926 }
3027
31- // include nullable too
32- // skip date time + date time interface, as should be kept
33- if ($ this ->nodeTypeResolver ->isObjectType ($ param ->type , new ObjectType ('DateTimeInterface ' ))) {
34- return null ;
35- }
36-
3728 $ staticType = $ this ->staticTypeMapper ->mapPhpParserNodePHPStanType ($ param ->type );
3829 $ expectedName = $ this ->propertyNaming ->getExpectedNameFromType ($ staticType );
3930
Original file line number Diff line number Diff line change @@ -118,11 +118,8 @@ public function resolveForCall(MethodCall | StaticCall | FuncCall $expr): ?strin
118118 return null ;
119119 }
120120
121- if ($ this ->isDateTimeType ($ returnedType )) {
122- return null ;
123- }
124-
125121 $ expectedName = $ this ->propertyNaming ->getExpectedNameFromType ($ returnedType );
122+
126123 if ($ expectedName instanceof ExpectedName) {
127124 return $ expectedName ->getName ();
128125 }
@@ -211,17 +208,4 @@ private function resolveReturnTypeFromArrayType(ArrayType $arrayType): ?Type
211208
212209 return $ arrayType ->getIterableValueType ();
213210 }
214-
215- /**
216- * Skip date time, as custom naming
217- */
218- private function isDateTimeType (ObjectType $ objectType ): bool
219- {
220- if ($ objectType ->isInstanceOf ('DateTimeInterface ' )->yes ()) {
221- return true ;
222- }
223-
224- return $ objectType ->isInstanceOf ('DateTime ' )
225- ->yes ();
226- }
227211}
Original file line number Diff line number Diff line change 1111use PHPStan \Type \ThisType ;
1212use PHPStan \Type \Type ;
1313use PHPStan \Type \TypeCombinator ;
14+ use Rector \Enum \ClassName ;
1415use Rector \Exception \ShouldNotHappenException ;
1516use Rector \Naming \RectorNamingInflector ;
1617use Rector \Naming \ValueObject \ExpectedName ;
@@ -71,6 +72,8 @@ public function getExpectedNameFromMethodName(string $methodName): ?ExpectedName
7172
7273 public function getExpectedNameFromType (Type $ type ): ?ExpectedName
7374 {
75+ $ type = TypeCombinator::removeNull ($ type );
76+
7477 // keep collections untouched
7578 if ($ type instanceof ObjectType) {
7679 if ($ type ->isInstanceOf ('Doctrine\Common\Collections\Collection ' )->yes ()) {
@@ -80,6 +83,10 @@ public function getExpectedNameFromType(Type $type): ?ExpectedName
8083 if ($ type ->isInstanceOf ('Illuminate\Support\Collection ' )->yes ()) {
8184 return null ;
8285 }
86+
87+ if ($ type ->isInstanceOf (ClassName::DATE_TIME_INTERFACE )->yes ()) {
88+ return null ;
89+ }
8390 }
8491
8592 $ className = $ this ->resolveClassNameFromType ($ type );
@@ -278,7 +285,6 @@ private function normalizeShortClassName(string $shortClassName): string
278285
279286 private function resolveClassNameFromType (Type $ type ): ?string
280287 {
281- $ type = TypeCombinator::removeNull ($ type );
282288 $ className = ClassNameFromObjectTypeResolver::resolve ($ type );
283289
284290 if ($ className === null ) {
Original file line number Diff line number Diff line change @@ -32,11 +32,6 @@ 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-
4035 if ($ this ->dateTimeAtNamingConventionGuard ->isConflicting ($ propertyRename )) {
4136 return true ;
4237 }
You can’t perform that action at this time.
0 commit comments