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