Skip to content

Commit

Permalink
minor #6215 DX: Doctrine\Annotation\Tokens - fix phpstan violations (…
Browse files Browse the repository at this point in the history
…keradus)

This PR was squashed before being merged into the master branch.

Discussion
----------

DX: Doctrine\Annotation\Tokens - fix phpstan violations

Commits
-------

5579859 DX: Doctrine\Annotation\Tokens - fix phpstan violations
  • Loading branch information
keradus committed Jan 2, 2022
2 parents 1b27f5c + 5579859 commit efeab76
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/Doctrine/Annotation/Tokens.php
Expand Up @@ -36,7 +36,7 @@ public static function createFromDocComment(PhpToken $input, array $ignoredTags
throw new \InvalidArgumentException('Input must be a T_DOC_COMMENT token.');
}

$tokens = new self();
$tokens = [];

$content = $input->getContent();
$ignoredTextPosition = 0;
Expand Down Expand Up @@ -127,6 +127,31 @@ public static function createFromDocComment(PhpToken $input, array $ignoredTags
$tokens[] = new Token(DocLexer::T_NONE, substr($content, $ignoredTextPosition));
}

return self::fromArray($tokens);
}

/**
* Create token collection from array.
*
* @param Token[] $array the array to import
* @param ?bool $saveIndices save the numeric indices used in the original array, default is yes
*/
public static function fromArray($array, $saveIndices = null): self
{
$tokens = new self(\count($array));

if (null === $saveIndices || $saveIndices) {
foreach ($array as $key => $val) {
$tokens[$key] = $val;
}
} else {
$index = 0;

foreach ($array as $val) {
$tokens[$index++] = $val;
}
}

return $tokens;
}

Expand Down Expand Up @@ -273,11 +298,6 @@ public function offsetSet($index, $token): void
));
}

if (null === $index) {
$index = \count($this);
$this->setSize($this->getSize() + 1);
}

parent::offsetSet($index, $token);
}

Expand Down

0 comments on commit efeab76

Please sign in to comment.