Skip to content

Commit

Permalink
[Php83] add string type to concat constant (#5516)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdohuutin committed Jan 29, 2024
1 parent 1608ae8 commit 52398c8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ final class ApplyTypesWhenClassFinal
public const NULL = null;

public const ARRAY = [];

public const CONCAT = self::STRING . 'concat';
}

?>
Expand All @@ -36,6 +38,8 @@ final class ApplyTypesWhenClassFinal
public const null NULL = null;

public const array ARRAY = [];

public const string CONCAT = self::STRING . 'concat';
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ApplyTypesToPrivateConsts
private const NULL = null;

private const ARRAY = [];

private const CONCAT = self::STRING . 'concat';
}

?>
Expand All @@ -36,6 +38,8 @@ class ApplyTypesToPrivateConsts
private const null NULL = null;

private const array ARRAY = [];

private const string CONCAT = self::STRING . 'concat';
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class SomeClass
{
public const string A = 'A';

public const B = self::A . 'b';
public const string B = self::A . 'b';

public const int INT = 1;

Expand Down
5 changes: 5 additions & 0 deletions rules/Php83/Rector/ClassConst/AddTypeToConstRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\Const_;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\DNumber;
Expand Down Expand Up @@ -165,6 +166,10 @@ private function findValueType(Expr $expr): ?Identifier
return new Identifier('array');
}

if ($expr instanceof Concat) {
return new Identifier('string');
}

return null;
}

Expand Down

0 comments on commit 52398c8

Please sign in to comment.