diff --git a/src/autoload.php b/src/autoload.php index d914165e..6e58b911 100644 --- a/src/autoload.php +++ b/src/autoload.php @@ -219,8 +219,7 @@ function($class) { 'theseer\\phpdox\\projectconfig' => '/config/ProjectConfig.php', 'theseer\\phpdox\\shellprogresslogger' => '/logger/ShellProgressLogger.php', 'theseer\\phpdox\\silentprogresslogger' => '/logger/SilentProgressLogger.php', - 'theseer\\phpdox\\typeawareinterface' => '/shared/TypeAwareInterface.php', - 'theseer\\phpdox\\typeawaretrait' => '/shared/TypeAwareTrait.php', + 'theseer\\phpdox\\typeinfo' => '/shared/TypeInfo.php', 'theseer\\phpdox\\version' => '/shared/Version.php' ); } diff --git a/src/collector/backend/parser/UnitCollectingVisitor.php b/src/collector/backend/parser/UnitCollectingVisitor.php index 06a883be..7121ab8d 100644 --- a/src/collector/backend/parser/UnitCollectingVisitor.php +++ b/src/collector/backend/parser/UnitCollectingVisitor.php @@ -21,11 +21,9 @@ use TheSeer\phpDox\Collector\InlineComment; use TheSeer\phpDox\Collector\MethodObject; use TheSeer\phpDox\DocBlock\Parser as DocBlockParser; -use TheSeer\phpDox\TypeAwareInterface; -use TheSeer\phpDox\TypeAwareTrait; +use TheSeer\phpDox\TypeInfo; -class UnitCollectingVisitor extends NodeVisitorAbstract implements TypeAwareInterface { - use TypeAwareTrait; +class UnitCollectingVisitor extends NodeVisitorAbstract { /** * @var \TheSeer\phpDox\DocBlock\Parser @@ -52,6 +50,11 @@ class UnitCollectingVisitor extends NodeVisitorAbstract implements TypeAwareInte */ private $unit; + /** + * @var TypeInfo + */ + private $typeInfo; + private $modifier = [ NodeType\Class_::MODIFIER_PUBLIC => 'public', NodeType\Class_::MODIFIER_PROTECTED => 'protected', @@ -61,6 +64,7 @@ class UnitCollectingVisitor extends NodeVisitorAbstract implements TypeAwareInte public function __construct(DocBlockParser $parser, ParseResult $result) { $this->docBlockParser = $parser; $this->result = $result; + $this->typeInfo = new TypeInfo(); } /** @@ -266,25 +270,27 @@ private function processMethodReturnType(MethodObject $method, $returnType): voi return; } - if ($this->isBuiltInType((string)$returnType, self::TYPE_RETURN)) { - $returnTypeObject = $method->setReturnType($returnType); + $stringReturnType = $returnType instanceof NullableType ? (string)$returnType->type:(string)$returnType; + + if ($this->typeInfo->isBuiltInType($stringReturnType, TypeInfo::TYPE_RETURN)) { + $returnTypeObject = $method->setReturnType($stringReturnType); $returnTypeObject->setNullable(false); return; } if ($returnType instanceof \PhpParser\Node\Name\FullyQualified) { - $returnTypeObject = $method->setReturnType($returnType->toString()); + $returnTypeObject = $method->setReturnType($stringReturnType); $returnTypeObject->setNullable(false); return; } if ($returnType instanceof NullableType) { - if ((string)$returnType->type === 'self') { + if ($stringReturnType === 'self') { $returnTypeObject = $method->setReturnType($this->unit->getName()); } else { - $returnTypeObject = $method->setReturnType($returnType->type); + $returnTypeObject = $method->setReturnType($stringReturnType); } $returnTypeObject->setNullable(true); diff --git a/src/collector/project/AbstractVariableObject.php b/src/collector/project/AbstractVariableObject.php index 320b513b..0e19b8fe 100644 --- a/src/collector/project/AbstractVariableObject.php +++ b/src/collector/project/AbstractVariableObject.php @@ -2,15 +2,12 @@ namespace TheSeer\phpDox\Collector; use TheSeer\fDOM\fDOMElement; -use TheSeer\phpDox\TypeAwareInterface; -use TheSeer\phpDox\TypeAwareTrait; +use TheSeer\phpDox\TypeInfo; /** * Class AbstractVariableObject */ -abstract class AbstractVariableObject implements TypeAwareInterface { - use TypeAwareTrait; - +abstract class AbstractVariableObject { public const XMLNS = 'http://xml.phpdox.net/src'; /** @@ -23,8 +20,14 @@ abstract class AbstractVariableObject implements TypeAwareInterface { */ private $types = []; + /** + * @var TypeInfo + */ + private $typeInfo; + public function __construct(fDOMElement $ctx) { - $this->ctx = $ctx; + $this->ctx = $ctx; + $this->typeInfo = new TypeInfo(); } public function export(): fDOMElement { @@ -65,7 +68,7 @@ public function setConstant($const): void { } public function isInternalType($type) { - return $this->isBuiltInType((string)$type) || \in_array(\mb_strtolower((string)$type), $this->types); + return $this->typeInfo->isBuiltInType((string)$type) || \in_array(\mb_strtolower((string)$type), $this->types); } /** diff --git a/src/docblock/elements/VarElement.php b/src/docblock/elements/VarElement.php index 8690b6c6..fb4952d0 100644 --- a/src/docblock/elements/VarElement.php +++ b/src/docblock/elements/VarElement.php @@ -1,14 +1,23 @@ typeInfo = new TypeInfo(); + } + + public function asDom(\TheSeer\fDOM\fDOMDocument $ctx) { $node = parent::asDom($ctx); $type = $node->getAttribute('type'); @@ -31,7 +40,7 @@ public function asDom(\TheSeer\fDOM\fDOMDocument $ctx) { $node->setAttribute('of', $type); } - if (!$this->isBuiltInType($type, self::TYPE_PHPDOC|self::TYPE_PHPDOX)) { + if (!$this->typeInfo->isBuiltInType($type, TypeInfo::TYPE_PHPDOC|TypeInfo::TYPE_PHPDOX)) { if (!$node->hasAttribute('of')) { $node->setAttribute('type', 'object'); } else { @@ -60,7 +69,7 @@ protected function typeResolver(\TheSeer\fDOM\fDOMElement $node, string $type) { $nodeType->setAttribute('full', $type); $nodeType->setAttribute('array', $isArray?'true':'false'); - if ($this->isBuiltInType($type, self::TYPE_PHPDOC|self::TYPE_PHPDOX)) { + if ($this->typeInfo->isBuiltInType($type, TypeInfo::TYPE_PHPDOC|TypeInfo::TYPE_PHPDOX)) { $nodeType->setAttribute('name', $type); $nodeType->setAttribute('namespace', ''); return; diff --git a/src/docblock/parser/GenericParser.php b/src/docblock/parser/GenericParser.php index 76d7fe12..7db68e60 100644 --- a/src/docblock/parser/GenericParser.php +++ b/src/docblock/parser/GenericParser.php @@ -1,11 +1,9 @@ factory = $factory; - $this->name = $name; + $this->factory = $factory; + $this->name = $name; + $this->typeInfo = new TypeInfo(); } public function setAliasMap(array $map): void { @@ -72,7 +76,7 @@ protected function lookupOneType($type) { } // Do not mess with scalar and fixed types - if ($this->isBuiltInType($type)) { + if ($this->typeInfo->isBuiltInType($type)) { return $type; } diff --git a/src/shared/TypeAwareInterface.php b/src/shared/TypeAwareInterface.php deleted file mode 100644 index ecdb1390..00000000 --- a/src/shared/TypeAwareInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -getBuiltInTypes($context), true); } }