2222 * However, unknown `AtRule`s (like `@font-face`) are rule sets as well.
2323 *
2424 * If you want to manipulate a `RuleSet`,
25- * use the methods `addRule ()`, `getRules ()`, `removeRule ()`, `removeMatchingRules ()`, etc.
25+ * use the methods `addDeclaration ()`, `getDeclarations ()`, `removeDeclaration ()`, `removeMatchingDeclarations ()`, etc.
2626 *
2727 * Note that `CSSListItem` extends both `Commentable` and `Renderable`, so those interfaces must also be implemented.
2828 */
2929class RuleSet implements CSSElement, CSSListItem, Positionable, RuleContainer
3030{
3131 use CommentContainer;
32+ use LegacyRuleContainerMethods;
3233 use Position;
3334
3435 /**
@@ -88,7 +89,7 @@ public static function parseRuleSet(ParserState $parserState, RuleSet $ruleSet):
8889 $ declaration = Declaration::parse ($ parserState , $ commentsBeforeDeclaration );
8990 }
9091 if ($ declaration instanceof Declaration) {
91- $ ruleSet ->addRule ($ declaration );
92+ $ ruleSet ->addDeclaration ($ declaration );
9293 }
9394 }
9495 $ parserState ->consume ('} ' );
@@ -99,7 +100,7 @@ public static function parseRuleSet(ParserState $parserState, RuleSet $ruleSet):
99100 * if the last `Declaration` is needed as a basis for setting position, but does not have a valid position,
100101 * which should never happen
101102 */
102- public function addRule (Declaration $ declarationToAdd , ?Declaration $ sibling = null ): void
103+ public function addDeclaration (Declaration $ declarationToAdd , ?Declaration $ sibling = null ): void
103104 {
104105 $ propertyName = $ declarationToAdd ->getPropertyName ();
105106 if (!isset ($ this ->declarations [$ propertyName ])) {
@@ -148,14 +149,14 @@ public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = n
148149 if ($ declarationToAdd ->getLineNumber () === null ) {
149150 //this node is added manually, give it the next best line
150151 $ columnNumber = $ declarationToAdd ->getColumnNumber () ?? 0 ;
151- $ declarations = $ this ->getRules ();
152+ $ declarations = $ this ->getDeclarations ();
152153 $ declarationsCount = \count ($ declarations );
153154 if ($ declarationsCount > 0 ) {
154155 $ last = $ declarations [$ declarationsCount - 1 ];
155156 $ lastsLineNumber = $ last ->getLineNumber ();
156157 if (!\is_int ($ lastsLineNumber )) {
157158 throw new \UnexpectedValueException (
158- 'A Declaration without a line number was found during addRule ' ,
159+ 'A Declaration without a line number was found during addDeclaration ' ,
159160 1750718399
160161 );
161162 }
@@ -173,9 +174,9 @@ public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = n
173174 /**
174175 * Returns all declarations matching the given property name
175176 *
176- * @example $ruleSet->getRules ('font') // returns array(0 => $declaration, …) or array().
177+ * @example $ruleSet->getDeclarations ('font') // returns array(0 => $declaration, …) or array().
177178 *
178- * @example $ruleSet->getRules ('font-')
179+ * @example $ruleSet->getDeclarations ('font-')
179180 * //returns an array of all declarations either beginning with font- or matching font.
180181 *
181182 * @param string|null $searchPattern
@@ -185,7 +186,7 @@ public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = n
185186 *
186187 * @return array<int<0, max>, Declaration>
187188 */
188- public function getRules (?string $ searchPattern = null ): array
189+ public function getDeclarations (?string $ searchPattern = null ): array
189190 {
190191 $ result = [];
191192 foreach ($ this ->declarations as $ propertyName => $ declarations ) {
@@ -214,11 +215,11 @@ public function getRules(?string $searchPattern = null): array
214215 *
215216 * @param array<Declaration> $declarations
216217 */
217- public function setRules (array $ declarations ): void
218+ public function setDeclarations (array $ declarations ): void
218219 {
219220 $ this ->declarations = [];
220221 foreach ($ declarations as $ declaration ) {
221- $ this ->addRule ($ declaration );
222+ $ this ->addDeclaration ($ declaration );
222223 }
223224 }
224225
@@ -238,11 +239,11 @@ public function setRules(array $declarations): void
238239 *
239240 * @return array<string, Declaration>
240241 */
241- public function getRulesAssoc (?string $ searchPattern = null ): array
242+ public function getDeclarationsAssociative (?string $ searchPattern = null ): array
242243 {
243244 /** @var array<string, Declaration> $result */
244245 $ result = [];
245- foreach ($ this ->getRules ($ searchPattern ) as $ declaration ) {
246+ foreach ($ this ->getDeclarations ($ searchPattern ) as $ declaration ) {
246247 $ result [$ declaration ->getPropertyName ()] = $ declaration ;
247248 }
248249
@@ -252,7 +253,7 @@ public function getRulesAssoc(?string $searchPattern = null): array
252253 /**
253254 * Removes a `Declaration` from this `RuleSet` by identity.
254255 */
255- public function removeRule (Declaration $ declarationToRemove ): void
256+ public function removeDeclaration (Declaration $ declarationToRemove ): void
256257 {
257258 $ nameOfPropertyToRemove = $ declarationToRemove ->getPropertyName ();
258259 if (!isset ($ this ->declarations [$ nameOfPropertyToRemove ])) {
@@ -274,7 +275,7 @@ public function removeRule(Declaration $declarationToRemove): void
274275 * all declarations starting with the pattern are removed as well as one matching the pattern with the dash
275276 * excluded.
276277 */
277- public function removeMatchingRules (string $ searchPattern ): void
278+ public function removeMatchingDeclarations (string $ searchPattern ): void
278279 {
279280 foreach ($ this ->declarations as $ propertyName => $ declarations ) {
280281 // Either the search pattern matches the found declaration's property name exactly
@@ -291,7 +292,7 @@ public function removeMatchingRules(string $searchPattern): void
291292 }
292293 }
293294
294- public function removeAllRules (): void
295+ public function removeAllDeclarations (): void
295296 {
296297 $ this ->declarations = [];
297298 }
@@ -301,15 +302,15 @@ public function removeAllRules(): void
301302 */
302303 public function render (OutputFormat $ outputFormat ): string
303304 {
304- return $ this ->renderRules ($ outputFormat );
305+ return $ this ->renderDeclarations ($ outputFormat );
305306 }
306307
307- protected function renderRules (OutputFormat $ outputFormat ): string
308+ protected function renderDeclarations (OutputFormat $ outputFormat ): string
308309 {
309310 $ result = '' ;
310311 $ isFirst = true ;
311312 $ nextLevelFormat = $ outputFormat ->nextLevel ();
312- foreach ($ this ->getRules () as $ declaration ) {
313+ foreach ($ this ->getDeclarations () as $ declaration ) {
313314 $ nextLevelFormatter = $ nextLevelFormat ->getFormatter ();
314315 $ renderedDeclaration = $ nextLevelFormatter ->safely (
315316 static function () use ($ declaration , $ nextLevelFormat ): string {
0 commit comments