Page MenuHomeWickedGov Phorge

TagWithType.php
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

TagWithType.php

<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tags;
use InvalidArgumentException;
use phpDocumentor\Reflection\Type;
use function in_array;
use function sprintf;
use function strlen;
use function substr;
use function trim;
abstract class TagWithType extends BaseTag
{
/** @var ?Type */
protected ?Type $type = null;
/**
* Returns the type section of the variable.
*/
public function getType(): ?Type
{
return $this->type;
}
/**
* @return string[]
*/
protected static function extractTypeFromBody(string $body): array
{
$type = '';
$nestingLevel = 0;
for ($i = 0, $iMax = strlen($body); $i < $iMax; $i++) {
$character = $body[$i];
if ($nestingLevel === 0 && trim($character) === '') {
break;
}
$type .= $character;
if (in_array($character, ['<', '(', '[', '{'])) {
$nestingLevel++;
continue;
}
if (in_array($character, ['>', ')', ']', '}'])) {
$nestingLevel--;
continue;
}
}
if ($nestingLevel < 0 || $nestingLevel > 0) {
throw new InvalidArgumentException(
sprintf('Could not find type in %s, please check for malformed notations', $body)
);
}
$description = trim(substr($body, strlen($type)));
return [$type, $description];
}
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
} else {
$description = '';
}
$type = (string) $this->type;
return $type . ($description !== '' ? ($type !== '' ? ' ' : '') . $description : '');
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, May 16, 17:56 (9 h, 25 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
7f/00/104c0cb8bedd38eb48d878e3e769
Default Alt Text
TagWithType.php (2 KB)

Event Timeline