@@ -73,7 +73,7 @@ public function getAllRuleSets(): array
73
73
* will be returned).
74
74
* @param bool $searchInFunctionArguments whether to also return `Value` objects used as `CSSFunction` arguments.
75
75
*
76
- * @return array<int, Value>
76
+ * @return list< Value>
77
77
*
78
78
* @see RuleSet->getRules()
79
79
*/
@@ -82,40 +82,52 @@ public function getAllValues(
82
82
?string $ ruleSearchPattern = null ,
83
83
bool $ searchInFunctionArguments = false
84
84
): array {
85
- $ result = [];
86
- $ this ->allValues ($ element ?? $ this , $ result , $ ruleSearchPattern , $ searchInFunctionArguments );
87
- return $ result ;
88
- }
85
+ $ element = $ element ?? $ this ;
89
86
90
- /**
91
- * @param CSSElement|string $element
92
- * @param list<Value> $result
93
- */
94
- protected function allValues (
95
- $ element ,
96
- array &$ result ,
97
- ?string $ searchString = null ,
98
- bool $ searchInFunctionArguments = false
99
- ): void {
87
+ $ result = [];
100
88
if ($ element instanceof CSSBlockList) {
101
- foreach ($ element ->getContents () as $ content ) {
102
- $ this ->allValues ($ content , $ result , $ searchString , $ searchInFunctionArguments );
89
+ foreach ($ element ->getContents () as $ contentItem ) {
90
+ // Statement at-rules are skipped since they do not contain values.
91
+ if ($ contentItem instanceof CSSElement) {
92
+ $ result = \array_merge (
93
+ $ result ,
94
+ $ this ->getAllValues ($ contentItem , $ ruleSearchPattern , $ searchInFunctionArguments )
95
+ );
96
+ }
103
97
}
104
98
} elseif ($ element instanceof RuleSet) {
105
- foreach ($ element ->getRules ($ searchString ) as $ rule ) {
106
- $ this ->allValues ($ rule , $ result , $ searchString , $ searchInFunctionArguments );
99
+ foreach ($ element ->getRules ($ ruleSearchPattern ) as $ rule ) {
100
+ $ result = \array_merge (
101
+ $ result ,
102
+ $ this ->getAllValues ($ rule , $ ruleSearchPattern , $ searchInFunctionArguments )
103
+ );
107
104
}
108
105
} elseif ($ element instanceof Rule) {
109
- $ this ->allValues ($ element ->getValue (), $ result , $ searchString , $ searchInFunctionArguments );
106
+ $ value = $ element ->getValue ();
107
+ // `string` values are discarded.
108
+ if ($ value instanceof CSSElement) {
109
+ $ result = \array_merge (
110
+ $ result ,
111
+ $ this ->getAllValues ($ value , $ ruleSearchPattern , $ searchInFunctionArguments )
112
+ );
113
+ }
110
114
} elseif ($ element instanceof ValueList) {
111
115
if ($ searchInFunctionArguments || !($ element instanceof CSSFunction)) {
112
116
foreach ($ element ->getListComponents () as $ component ) {
113
- $ this ->allValues ($ component , $ result , $ searchString , $ searchInFunctionArguments );
117
+ // `string` components are discarded.
118
+ if ($ component instanceof CSSElement) {
119
+ $ result = \array_merge (
120
+ $ result ,
121
+ $ this ->getAllValues ($ component , $ ruleSearchPattern , $ searchInFunctionArguments )
122
+ );
123
+ }
114
124
}
115
125
}
116
126
} elseif ($ element instanceof Value) {
117
127
$ result [] = $ element ;
118
128
}
129
+
130
+ return $ result ;
119
131
}
120
132
121
133
/**
0 commit comments