-
Notifications
You must be signed in to change notification settings - Fork 75
/
ArgumentInvocation.php
127 lines (108 loc) · 2.61 KB
/
ArgumentInvocation.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* SCSSPHP
*
* @copyright 2012-2020 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
* @link http://scssphp.github.io/scssphp
*/
namespace ScssPhp\ScssPhp\Ast\Sass;
use ScssPhp\ScssPhp\SourceSpan\FileSpan;
/**
* A set of arguments passed in to a function or mixin.
*
* @internal
*/
final class ArgumentInvocation implements SassNode
{
/**
* @var list<Expression>
* @readonly
*/
private $positional;
/**
* @var array<string, Expression>
* @readonly
*/
private $named;
/**
* @var Expression|null
* @readonly
*/
private $rest;
/**
* @var Expression|null
*/
private $keywordRest;
/**
* @var FileSpan
* @readonly
*/
private $span;
/**
* @param list<Expression> $positional
* @param array<string, Expression> $named
* @param FileSpan $span
* @param Expression|null $rest
* @param Expression|null $keywordRest
*/
public function __construct(array $positional, array $named, FileSpan $span, ?Expression $rest = null, ?Expression $keywordRest = null)
{
assert($keywordRest === null || $rest !== null);
$this->positional = $positional;
$this->named = $named;
$this->rest = $rest;
$this->keywordRest = $keywordRest;
$this->span = $span;
}
public static function createEmpty(FileSpan $span): ArgumentInvocation
{
return new self([], [], $span);
}
public function isEmpty(): bool
{
return \count($this->positional) === 0 && \count($this->named) === 0 && $this->rest === null;
}
/**
* @return list<Expression>
*/
public function getPositional(): array
{
return $this->positional;
}
/**
* @return array<string, Expression>
*/
public function getNamed(): array
{
return $this->named;
}
public function getRest(): ?Expression
{
return $this->rest;
}
public function getKeywordRest(): ?Expression
{
return $this->keywordRest;
}
public function getSpan(): FileSpan
{
return $this->span;
}
public function __toString(): string
{
$parts = $this->positional;
foreach ($this->named as $name => $arg) {
$parts[] = "\$$name: $arg";
}
if ($this->rest !== null) {
$parts[] = "$this->rest...";
}
if ($this->keywordRest !== null) {
$parts[] = "$this->keywordRest...";
}
return '(' . implode(', ', $parts) . ')';
}
}