Skip to content

Commit

Permalink
BinaryOpBetweenNumberAndStringRector don't trust phpdoc (#5199)
Browse files Browse the repository at this point in the history
* BinaryOpBetweenNumberAndStringRector don't trust phpdoc

* Update skip_phpdoc.php.inc
  • Loading branch information
staabm committed Oct 25, 2023
1 parent 98bb858 commit 5d12860
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/NodeTypeResolver/NodeTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function getNativeType(Expr $expr): Type

public function isNumberType(Expr $expr): bool
{
$nodeType = $this->getType($expr);
$nodeType = $this->getNativeType($expr);
if ($nodeType->isInteger()->yes()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\Tests\Php71\Rector\BinaryOp\BinaryOpBetweenNumberAndStringRector\Fixture;

class SkipPhpdoc
{
/**
* @var int
*/
public $adresseid_lieferung;

public function run()
{
if ('' == $this->adresseid_lieferung) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ public function refactor(Node $node): ?Node
return null;
}

if ($this->isStringOrStaticNonNumbericString($node->left) && $this->nodeTypeResolver->isNumberType(
if ($this->isStringOrStaticNonNumericString($node->left) && $this->nodeTypeResolver->isNumberType(
$node->right
)) {
$node->left = new LNumber(0);

return $node;
}

if ($this->isStringOrStaticNonNumbericString($node->right) && $this->nodeTypeResolver->isNumberType(
if ($this->isStringOrStaticNonNumericString($node->right) && $this->nodeTypeResolver->isNumberType(
$node->left
)) {
$node->right = new LNumber(0);
Expand All @@ -119,7 +119,7 @@ public function refactor(Node $node): ?Node
return null;
}

private function isStringOrStaticNonNumbericString(Expr $expr): bool
private function isStringOrStaticNonNumericString(Expr $expr): bool
{
// replace only scalar values, not variables/constants/etc.
if (! $expr instanceof Scalar && ! $expr instanceof Variable) {
Expand Down

0 comments on commit 5d12860

Please sign in to comment.