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,12 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector\Fixture;

final class KeepDate
{
private function getItemByRefOrNull(?\DateTime $startDate)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Rector\DeadCode\Rector\If_;

use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node\Param;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\Naming\Naming\PropertyNaming;
use Rector\Naming\ValueObject\ExpectedName;
use Rector\StaticTypeMapper\StaticTypeMapper;
Expand All @@ -29,7 +30,7 @@ public function resolve(Param $param): ?string

// include nullable too
// skip date time + date time interface, as should be kept
if ($staticType->isSuperTypeOf(new ObjectType('DateTimeInterface'))->yes()) {
if ($this->isDateTimeType($staticType)) {
return null;
}

Expand All @@ -40,4 +41,14 @@ public function resolve(Param $param): ?string

return $expectedName->getName();
}

private function isDateTimeType(Type $type): bool
{
if ($type->isSuperTypeOf(new ObjectType('DateTimeInterface'))->yes()) {
return true;
}

return $type->isSuperTypeOf(new ObjectType('DateTime'))
->yes();
}
}
2 changes: 1 addition & 1 deletion src/PhpParser/Node/BetterNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static function (Node $subNode) use ($types, &$isFoundNode): ?int {
* @return T[]
*/
public function findInstancesOfInFunctionLikeScoped(
ClassMethod | Function_ | Closure $functionLike,
ClassMethod | Function_ | Closure $functionLike,
string|array $types
): array {
if (is_string($types)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DowngradePhp81\Rector\StmtsAwareInterface\DowngradeSetAccessibleReflectionPropertyRector;
use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector;
use Rector\DowngradePhp81\Rector\StmtsAwareInterface\DowngradeSetAccessibleReflectionPropertyRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
DowngradeSetAccessibleReflectionPropertyRector::class,
DowngradeMatchToSwitchRector::class,
DowngradeSetAccessibleReflectionPropertyRector::class,
DowngradeMatchToSwitchRector::class,
]);
};