Skip to content

Commit

Permalink
[ci-review] Rector Rectify
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user authored and TomasVotruba committed Jul 16, 2024
1 parent cfb8514 commit 43868ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 4 additions & 3 deletions rules/CodeQuality/NodeFactory/TypedPropertyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\CodeQuality\NodeFactory;

use PhpParser\Node\NullableType;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
Expand All @@ -12,7 +13,7 @@
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\StaticTypeMapper\StaticTypeMapper;

final class TypedPropertyFactory
final readonly class TypedPropertyFactory
{
public function __construct(
private StaticTypeMapper $staticTypeMapper,
Expand Down Expand Up @@ -42,8 +43,8 @@ public function createPropertyTypeNode(

$typeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($propertyType, TypeKind::PROPERTY);

if ($isNullable && ! $typeNode instanceof Node\NullableType) {
return new Node\NullableType($typeNode);
if ($isNullable && ! $typeNode instanceof NullableType) {
return new NullableType($typeNode);
}

return $typeNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\CodeQuality\Rector\Class_;

use PhpParser\Node\Attribute;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt\Class_;
Expand Down Expand Up @@ -88,7 +89,7 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if (! $this->attributeFinder->findAttributeByClass($node, 'AllowDynamicProperties')) {
if (!$this->attributeFinder->findAttributeByClass($node, 'AllowDynamicProperties') instanceof Attribute) {
return null;
}

Expand Down Expand Up @@ -158,11 +159,7 @@ private function createNewPropertyFromPropertyTagValueNodes(array $propertyPhpDo
}

$defaultValue = $existingProperty->props[0]->default;
if ($defaultValue instanceof Expr && $this->valueResolver->isNull($defaultValue)) {
$isNullable = true;
} else {
$isNullable = false;
}
$isNullable = $defaultValue instanceof Expr && $this->valueResolver->isNull($defaultValue);

$existingProperty->type = $this->typedPropertyFactory->createPropertyTypeNode(
$propertyTagValueNode,
Expand Down

0 comments on commit 43868ca

Please sign in to comment.