25
25
abstract class RuleSet implements Renderable, Commentable
26
26
{
27
27
/**
28
- * the rules in this rule set, using the property name as the key
28
+ * the rules in this rule set, using the property or rule name as the key
29
29
*
30
30
* @var array<string, Rule>
31
31
*/
@@ -105,15 +105,15 @@ public function getLineNo(): int
105
105
106
106
public function addRule (Rule $ ruleToAdd , ?Rule $ sibling = null ): void
107
107
{
108
- $ propertyName = $ ruleToAdd ->getRule ();
109
- if (!isset ($ this ->rules [$ propertyName ])) {
110
- $ this ->rules [$ propertyName ] = [];
108
+ $ propertyOrRuleName = $ ruleToAdd ->getRule ();
109
+ if (!isset ($ this ->rules [$ propertyOrRuleName ])) {
110
+ $ this ->rules [$ propertyOrRuleName ] = [];
111
111
}
112
112
113
- $ position = \count ($ this ->rules [$ propertyName ]);
113
+ $ position = \count ($ this ->rules [$ propertyOrRuleName ]);
114
114
115
115
if ($ sibling !== null ) {
116
- $ siblingPosition = \array_search ($ sibling , $ this ->rules [$ propertyName ], true );
116
+ $ siblingPosition = \array_search ($ sibling , $ this ->rules [$ propertyOrRuleName ], true );
117
117
if ($ siblingPosition !== false ) {
118
118
$ position = $ siblingPosition ;
119
119
$ ruleToAdd ->setPosition ($ sibling ->getLineNo (), $ sibling ->getColNo () - 1 );
@@ -129,7 +129,7 @@ public function addRule(Rule $ruleToAdd, ?Rule $sibling = null): void
129
129
}
130
130
}
131
131
132
- \array_splice ($ this ->rules [$ propertyName ], $ position , 0 , [$ ruleToAdd ]);
132
+ \array_splice ($ this ->rules [$ propertyOrRuleName ], $ position , 0 , [$ ruleToAdd ]);
133
133
}
134
134
135
135
/**
@@ -155,15 +155,15 @@ public function getRules($searchPattern = null)
155
155
}
156
156
/** @var array<int, Rule> $result */
157
157
$ result = [];
158
- foreach ($ this ->rules as $ propertyName => $ rule ) {
158
+ foreach ($ this ->rules as $ propertyOrRuleName => $ rule ) {
159
159
// Either no search rule is given or the search rule matches the found rule exactly
160
160
// or the search rule ends in “-” and the found rule starts with the search rule.
161
161
if (
162
- !$ searchPattern || $ propertyName === $ searchPattern
162
+ !$ searchPattern || $ propertyOrRuleName === $ searchPattern
163
163
|| (
164
164
\strrpos ($ searchPattern , '- ' ) === \strlen ($ searchPattern ) - \strlen ('- ' )
165
- && (\strpos ($ propertyName , $ searchPattern ) === 0
166
- || $ propertyName === \substr ($ searchPattern , 0 , -1 ))
165
+ && (\strpos ($ propertyOrRuleName , $ searchPattern ) === 0
166
+ || $ propertyOrRuleName === \substr ($ searchPattern , 0 , -1 ))
167
167
)
168
168
) {
169
169
$ result = \array_merge ($ result , $ rule );
0 commit comments