rector/packages/BetterPhpDocParser/ValueObject/PhpDoc/DoctrineAnnotation/CurlyListNode.php
Tomas Votruba 764b0a2692 Updated Rector to commit cb5b01223d46272004e947f122ae1e36d516f83a
cb5b01223d [automated] Re-Generate Nodes/Rectors Documentation (#3259)
2023-01-01 00:36:31 +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 RectorPrefix202301\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 . '}';
}
}