-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathCurlyListNode.php
More file actions
51 lines (42 loc) · 1.24 KB
/
CurlyListNode.php
File metadata and controls
51 lines (42 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Stringable;
use Webmozart\Assert\Assert;
final class CurlyListNode extends AbstractValuesAwareNode implements Stringable
{
/**
* @param ArrayItemNode[] $arrayItemNodes
*/
public function __construct(
private readonly array $arrayItemNodes = []
) {
Assert::allIsInstanceOf($this->arrayItemNodes, ArrayItemNode::class);
parent::__construct($this->arrayItemNodes);
}
public function __toString(): string
{
// possibly list items
return $this->implode($this->values);
}
/**
* @param ArrayItemNode[] $array
*/
private function implode(array $array): string
{
$itemContents = '';
$lastItemKey = array_key_last($array);
foreach ($array as $key => $value) {
if (is_int($key)) {
$itemContents .= (string) $value;
} else {
$itemContents .= $key . '=' . $value;
}
if ($lastItemKey !== $key) {
$itemContents .= ', ';
}
}
return '{' . $itemContents . '}';
}
}