2021-04-04 09:01:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation;
|
|
|
|
|
2021-04-05 08:40:13 +00:00
|
|
|
final class CurlyListNode extends AbstractValuesAwareNode
|
2021-04-04 09:01:11 +00:00
|
|
|
{
|
|
|
|
public function __toString(): string
|
|
|
|
{
|
|
|
|
$itemContents = '';
|
2021-04-05 08:40:13 +00:00
|
|
|
$lastItemKey = array_key_last($this->values);
|
2021-04-04 09:01:11 +00:00
|
|
|
|
2021-04-05 08:40:13 +00:00
|
|
|
foreach ($this->values as $key => $value) {
|
2021-04-04 09:01:11 +00:00
|
|
|
if (is_int($key)) {
|
|
|
|
$itemContents .= $this->stringifyValue($value);
|
|
|
|
} else {
|
|
|
|
$itemContents .= $key . '=' . $this->stringifyValue($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($lastItemKey !== $key) {
|
|
|
|
$itemContents .= ', ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return '{' . $itemContents . '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $value
|
|
|
|
*/
|
|
|
|
private function stringifyValue($value): string
|
|
|
|
{
|
|
|
|
if ($value === false) {
|
|
|
|
return 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($value === true) {
|
|
|
|
return 'true';
|
|
|
|
}
|
|
|
|
|
2021-04-13 18:51:41 +00:00
|
|
|
if (is_array($value)) {
|
|
|
|
return implode(', ', $value);
|
|
|
|
}
|
|
|
|
|
2021-04-04 09:01:11 +00:00
|
|
|
return (string) $value;
|
|
|
|
}
|
|
|
|
}
|