Skip to content

Commit

Permalink
Import PhpParser classes
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Jan 7, 2018
1 parent eb803eb commit 08e7dc3
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/collector/backend/parser/UnitCollectingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
*/
namespace TheSeer\phpDox\Collector\Backend {

use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\UnaryMinus;
use PhpParser\Node\Expr\UnaryPlus;
use PhpParser\Node\NullableType;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\MagicConst;
use PhpParser\Node\Scalar\String_;
use TheSeer\phpDox\Collector\AbstractUnitObject;
use TheSeer\phpDox\Collector\AbstractVariableObject;
use TheSeer\phpDox\Collector\InlineComment;
Expand Down Expand Up @@ -271,7 +283,7 @@ private function processMethodReturnType(MethodObject $method, $returnType) {
return;
}

if ($returnType instanceof \PhpParser\Node\NullableType) {
if ($returnType instanceof NullableType) {
if ((string)$returnType->type === 'self') {
$returnTypeObject = $method->setReturnType($this->unit->getName());
} else {
Expand Down Expand Up @@ -366,7 +378,7 @@ private function processProperty(NodeType\Property $node) {
}

private function setVariableType(AbstractVariableObject $variable, $type = NULL) {
if ($type instanceof \PhpParser\Node\NullableType) {
if ($type instanceof NullableType) {
$variable->setNullable(true);
$type = $type->type;
}
Expand Down Expand Up @@ -395,46 +407,46 @@ private function setVariableType(AbstractVariableObject $variable, $type = NULL)
$variable->setType($type);
}

private function resolveExpressionValue(\PhpParser\Node\Expr $expr) {
if ($expr instanceof \PhpParser\Node\Scalar\String_) {
private function resolveExpressionValue(Expr $expr) {
if ($expr instanceof String_) {
return array(
'type' => 'string',
'value' => $expr->getAttribute('originalValue')
);
}

if ($expr instanceof \PhpParser\Node\Scalar\LNumber ||
$expr instanceof \PhpParser\Node\Expr\UnaryMinus ||
$expr instanceof \PhpParser\Node\Expr\UnaryPlus) {
if ($expr instanceof LNumber ||
$expr instanceof UnaryMinus ||
$expr instanceof UnaryPlus) {
return array(
'type' => 'integer',
'value' => $expr->getAttribute('originalValue')
);
}

if ($expr instanceof \PhpParser\Node\Scalar\DNumber) {
if ($expr instanceof DNumber) {
return array(
'type' => 'float',
'value' => $expr->getAttribute('originalValue')
);
}

if ($expr instanceof \PhpParser\Node\Expr\Array_) {
if ($expr instanceof Array_) {
return array(
'type' => 'array',
'value' => '' // @todo add array2xml?
);
}

if ($expr instanceof \PhpParser\Node\Expr\ClassConstFetch) {
if ($expr instanceof ClassConstFetch) {
return array(
'type' => '{unknown}',
'value' => '',
'constant' => implode('\\', $expr->class->parts) . '::' . $expr->name
);
}

if ($expr instanceof \PhpParser\Node\Expr\ConstFetch) {
if ($expr instanceof ConstFetch) {
$reference = implode('\\', $expr->name->parts);
if (strtolower($reference) === 'null') {
return array(
Expand All @@ -454,15 +466,15 @@ private function resolveExpressionValue(\PhpParser\Node\Expr $expr) {
);
}

if ($expr instanceof \PhpParser\Node\Scalar\MagicConst\Line) {
if ($expr instanceof MagicConst\Line) {
return array(
'type' => 'integer',
'value' => '',
'constant' => $expr->getName()
);
}

if ($expr instanceof \PhpParser\Node\Scalar\MagicConst) {
if ($expr instanceof MagicConst) {
return array(
'type' => 'string',
'value' => '',
Expand All @@ -478,11 +490,12 @@ private function resolveExpressionValue(\PhpParser\Node\Expr $expr) {
}

/**
* @param AbstractVariableObject $variable
* @param \PhpParser\Node\Expr $default
* @return string
* @param AbstractVariableObject $variable
* @param Expr $default
*
* @throws ParseErrorException
*/
private function setVariableDefaultValue(AbstractVariableObject $variable, \PhpParser\Node\Expr $default = NULL) {
private function setVariableDefaultValue(AbstractVariableObject $variable, Expr $default = NULL) {
if ($default === NULL) {
return;
}
Expand All @@ -498,6 +511,5 @@ private function setVariableDefaultValue(AbstractVariableObject $variable, \PhpP
$variable->setConstant($resolved['constant']);
}
}

}
}

0 comments on commit 08e7dc3

Please sign in to comment.