Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Apr 24, 2023
1 parent d875bd4 commit 8090604
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Flip objectType control from null compare to use exclusive instanceof objectType', [
return new RuleDefinition('Flip type control from null compare to use exclusive instanceof object', [
new CodeSample(
<<<'CODE_SAMPLE'
function process(?DateTime $dateTime)
Expand Down
9 changes: 1 addition & 8 deletions rules/Strict/NodeFactory/ExactCompareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ private function collectCompareExprs(UnionType $unionType, Expr $expr, bool $tre
return $compareExprs;
}

private function cleanUpPossibleNullableUnionType(UnionType $unionType): Type
{
return count($unionType->getTypes()) === 2
? TypeCombinator::removeNull($unionType)
: $unionType;
}

/**
* @param array<Identical|BooleanOr|NotIdentical|BooleanAnd|Instanceof_|BooleanNot|null> $compareExprs
*/
Expand Down Expand Up @@ -200,7 +193,7 @@ private function createTruthyFromUnionType(
Expr $expr,
bool $treatAsNonEmpty
): BooleanOr|NotIdentical|Identical|BooleanNot|Instanceof_|BooleanAnd|null {
$unionType = $this->cleanUpPossibleNullableUnionType($unionType);
$unionType = TypeCombinator::removeNull($unionType);

if ($unionType instanceof UnionType) {
$compareExprs = $this->collectCompareExprs($unionType, $expr, $treatAsNonEmpty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PhpParser\Node\Stmt\Function_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Core\Php\PhpVersionProvider;
Expand Down Expand Up @@ -156,10 +155,6 @@ private function updateParamTagsIfRequired(
$paramTagValueNodes = $phpDocNode->getParamTagValues();
$paramTagWasUpdated = false;
foreach ($paramTagValueNodes as $paramTagValueNode) {
if (! $paramTagValueNode->type instanceof TypeNode) {
continue;
}

$param = $this->paramAnalyzer->getParamByName($paramTagValueNode->parameterName, $node);
if (! $param instanceof Param) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\Php\PhpVersionProvider;
Expand Down Expand Up @@ -105,10 +104,6 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $varTagValueNode->type instanceof TypeNode) {
return null;
}

$docType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($varTagValueNode->type, $node);

$updatedPhpDocType = $this->phpDocNullableTypeHelper->resolveUpdatedPhpDocTypeFromPhpDocTypeAndPhpParserType(
Expand Down

0 comments on commit 8090604

Please sign in to comment.