Skip to content

Commit

Permalink
Merge 7d0833a into e030609
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Jul 18, 2020
2 parents e030609 + 7d0833a commit 94d8111
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/voku/SimplePhpParser/Model/PHPDefineConstant.php
Expand Up @@ -5,6 +5,7 @@
namespace voku\SimplePhpParser\Model;

use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use voku\SimplePhpParser\Parsers\Helper\Utils;

class PHPDefineConstant extends PHPConst
Expand All @@ -19,23 +20,12 @@ public function readObjectFromPhpNode($node, $dummy = null): PHPConst
{
$this->prepareNode($node);

$constName = '';
if (
\count($node->args) > 0
&&
\property_exists($node->args[0], 'value')
&&
\property_exists($node->args[0]->value, 'value')
&&
$node->args[0]->value instanceof \PhpParser\Node\Scalar\String_
) {
$constName = (string) $node->args[0]->value->value;
}
$constName = $this->getConstantFQN($node, $constName);
$constName = (isset($node->args[0]->value->value) && $node->args[0]->value instanceof String_)
? $this->getConstantFQN($node, (string) $node->args[0]->value->value)
: '';
if (\in_array($constName, ['null', 'true', 'false'], true)) {
$constName = \strtoupper($constName);
}

$this->name = $constName;

$this->value = Utils::getPhpParserValueFromNode($node->args[1]);
Expand All @@ -57,18 +47,15 @@ public function readObjectFromBetterReflection($constant): PHPConst
$this->name = (string) $constant[0];

$constantValue = $constant[1];
if ($constantValue !== null) {
$this->type = Utils::normalizePhpType(\gettype($this->value));

if (\is_resource($constantValue)) {
$this->value = '__RESOURCE__';
} else {
$this->value = $constantValue;
}
} else {
if ($constantValue === null) {
$this->value = null;
return $this;
}

$this->type = Utils::normalizePhpType(\gettype($this->value));

$this->value = \is_resource($constantValue) ? '__RESOURCE__' : $constantValue;

return $this;
}
}

0 comments on commit 94d8111

Please sign in to comment.