2021-04-04 09:01:11 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation;
|
2021-04-04 09:01:11 +00:00
|
|
|
|
2021-05-29 22:10:59 +00:00
|
|
|
use Stringable;
|
2022-06-06 17:12:56 +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
|
|
|
{
|
2021-06-23 12:46:02 +00:00
|
|
|
return $this->implode($this->values);
|
2021-04-04 09:01:11 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @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)) {
|
2021-06-23 12:46:02 +00:00
|
|
|
return $this->implode($value);
|
2021-04-13 18:51:41 +00:00
|
|
|
}
|
2021-04-04 09:01:11 +00:00
|
|
|
return (string) $value;
|
|
|
|
}
|
2021-06-23 12:46:02 +00:00
|
|
|
/**
|
|
|
|
* @param mixed[] $array
|
|
|
|
*/
|
2021-07-05 23:06:30 +00:00
|
|
|
private function implode(array $array) : string
|
2021-06-23 12:46:02 +00:00
|
|
|
{
|
|
|
|
$itemContents = '';
|
|
|
|
\end($array);
|
|
|
|
$lastItemKey = \key($array);
|
|
|
|
foreach ($array as $key => $value) {
|
|
|
|
if (\is_int($key)) {
|
|
|
|
$itemContents .= $this->stringifyValue($value);
|
|
|
|
} else {
|
|
|
|
$itemContents .= $key . '=' . $this->stringifyValue($value);
|
|
|
|
}
|
|
|
|
if ($lastItemKey !== $key) {
|
|
|
|
$itemContents .= ', ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '{' . $itemContents . '}';
|
|
|
|
}
|
2021-04-04 09:01:11 +00:00
|
|
|
}
|