rector/packages/BetterPhpDocParser/ValueObject/PhpDoc/DoctrineAnnotation/CurlyListNode.php
Tomas Votruba 184cf49468 Updated Rector to commit f9de5d311e7e69d1ad2cb5f3087970d8b9335920
f9de5d311e [Php80] Handle RenameClassRector+AnnotationToAttributeRector with auto import and existing attribute defined (#5219)
2023-11-02 03:20:18 +00:00

51 lines
1.4 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Stringable;
use RectorPrefix202311\Webmozart\Assert\Assert;
final class CurlyListNode extends \Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\AbstractValuesAwareNode
{
/**
* @var ArrayItemNode[]
* @readonly
*/
private $arrayItemNodes = [];
/**
* @param ArrayItemNode[] $arrayItemNodes
*/
public function __construct(array $arrayItemNodes = [])
{
$this->arrayItemNodes = $arrayItemNodes;
Assert::allIsInstanceOf($this->arrayItemNodes, ArrayItemNode::class);
parent::__construct($this->arrayItemNodes);
}
public function __toString() : string
{
// possibly list items
return $this->implode($this->values);
}
/**
* @param mixed[] $array
*/
private function implode(array $array) : string
{
$itemContents = '';
\end($array);
$lastItemKey = \key($array);
foreach ($array as $key => $value) {
if (\is_int($key)) {
$itemContents .= (string) $value;
} else {
$itemContents .= $key . '=' . $value;
}
if ($lastItemKey !== $key) {
$itemContents .= ', ';
}
}
return '{' . $itemContents . '}';
}
}