Skip to content

Commit 4429cc2

Browse files
authored
[TASK] Remove original getAllValues() API (#1243)
The method still exists with the same (slightly improved) functionality, but the optional arguments have been refactored, and may require changes. Part of #994. Closes #1230.
1 parent 0119435 commit 4429cc2

File tree

4 files changed

+15
-74
lines changed

4 files changed

+15
-74
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ Please also have a look at our
6161

6262
### Removed
6363

64+
- Passing a string as the first argument to `getAllValues()` is no longer
65+
supported and will not work;
66+
the search pattern should now be passed as the second argument (#1243)
67+
- Passing a Boolean as the second argument to `getAllValues()` is no longer
68+
supported and will not work; the flag for searching in function arguments
69+
should now be passed as the third argument (#1243)
6470
- Remove `__toString()` (#1046)
6571
- Drop magic method forwarding in `OutputFormat` (#898)
6672
- Drop `atRuleArgs()` from the `AtRule` interface (#1141)

src/CSSList/CSSBlockList.php

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,46 +64,26 @@ public function getAllRuleSets(): array
6464
/**
6565
* Returns all `Value` objects found recursively in `Rule`s in the tree.
6666
*
67-
* @param CSSElement|string|null $element
67+
* @param CSSElement|null $element
6868
* This is the `CSSList` or `RuleSet` to start the search from (defaults to the whole document).
69-
* If a string is given, it is used as a rule name filter.
70-
* Passing a string for this parameter is deprecated in version 8.9.0, and will not work from v9.0;
71-
* use the following parameter to pass a rule name filter instead.
72-
* @param string|bool|null $ruleSearchPatternOrSearchInFunctionArguments
69+
* @param string|null $ruleSearchPattern
7370
* This allows filtering rules by property name
7471
* (e.g. if "color" is passed, only `Value`s from `color` properties will be returned,
7572
* or if "font-" is provided, `Value`s from all font rules, like `font-size`, and including `font` itself,
7673
* will be returned).
77-
* If a Boolean is provided, it is treated as the `$searchInFunctionArguments` argument.
78-
* Passing a Boolean for this parameter is deprecated in version 8.9.0, and will not work from v9.0;
79-
* use the `$searchInFunctionArguments` parameter instead.
80-
* @param bool $searchInFunctionArguments whether to also return Value objects used as Function arguments.
74+
* @param bool $searchInFunctionArguments whether to also return `Value` objects used as `CSSFunction` arguments.
8175
*
8276
* @return array<int, Value>
8377
*
8478
* @see RuleSet->getRules()
8579
*/
8680
public function getAllValues(
87-
$element = null,
88-
$ruleSearchPatternOrSearchInFunctionArguments = null,
81+
?CSSElement $element = null,
82+
?string $ruleSearchPattern = null,
8983
bool $searchInFunctionArguments = false
9084
): array {
91-
if (\is_bool($ruleSearchPatternOrSearchInFunctionArguments)) {
92-
$searchInFunctionArguments = $ruleSearchPatternOrSearchInFunctionArguments;
93-
$searchString = null;
94-
} else {
95-
$searchString = $ruleSearchPatternOrSearchInFunctionArguments;
96-
}
97-
98-
if ($element === null) {
99-
$element = $this;
100-
} elseif (\is_string($element)) {
101-
$searchString = $element;
102-
$element = $this;
103-
}
104-
10585
$result = [];
106-
$this->allValues($element, $result, $searchString, $searchInFunctionArguments);
86+
$this->allValues($element ?? $this, $result, $ruleSearchPattern, $searchInFunctionArguments);
10787
return $result;
10888
}
10989

tests/ParserTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function colorParsing(): void
153153
self::assertEmpty($colorRules);
154154
}
155155
}
156-
foreach ($document->getAllValues('color') as $colorValue) {
156+
foreach ($document->getAllValues(null, 'color') as $colorValue) {
157157
self::assertSame('red', $colorValue);
158158
}
159159
self::assertSame(
@@ -455,15 +455,15 @@ public function functionSyntax(): void
455455
. '.collapser.expanded + * {height: auto;}';
456456
self::assertSame($expected, $document->render());
457457

458-
foreach ($document->getAllValues(null, true) as $value) {
458+
foreach ($document->getAllValues(null, null, true) as $value) {
459459
if ($value instanceof Size && $value->isSize()) {
460460
$value->setSize($value->getSize() * 3);
461461
}
462462
}
463463
$expected = \str_replace(['1.2em', '.2em', '60%'], ['3.6em', '.6em', '180%'], $expected);
464464
self::assertSame($expected, $document->render());
465465

466-
foreach ($document->getAllValues(null, true) as $value) {
466+
foreach ($document->getAllValues(null, null, true) as $value) {
467467
if ($value instanceof Size && !$value->isRelative() && !$value->isColorComponent()) {
468468
$value->setSize($value->getSize() * 2);
469469
}

tests/Unit/CSSList/CSSBlockListTest.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -425,30 +425,6 @@ public function getAllValuesWithSearchStringProvidedReturnsOnlyValuesFromMatchin
425425
$declarationBlock->addRule($rule2);
426426
$subject->setContents([$declarationBlock]);
427427

428-
$result = $subject->getAllValues('font-');
429-
430-
self::assertSame([$value1], $result);
431-
}
432-
433-
/**
434-
* @test
435-
*/
436-
public function getAllValuesWithSearchStringProvidedInNewMethodSignatureReturnsOnlyValuesFromMatchingRules(): void
437-
{
438-
$subject = new ConcreteCSSBlockList();
439-
440-
$value1 = new CSSString('Superfont');
441-
$value2 = new CSSString('aquamarine');
442-
443-
$declarationBlock = new DeclarationBlock();
444-
$rule1 = new Rule('font-family');
445-
$rule1->setValue($value1);
446-
$declarationBlock->addRule($rule1);
447-
$rule2 = new Rule('color');
448-
$rule2->setValue($value2);
449-
$declarationBlock->addRule($rule2);
450-
$subject->setContents([$declarationBlock]);
451-
452428
$result = $subject->getAllValues(null, 'font-');
453429

454430
self::assertSame([$value1], $result);
@@ -491,27 +467,6 @@ public function getAllValuesWithSearchInFunctionArgumentsReturnsValuesInFunction
491467
$declarationBlock->addRule($rule);
492468
$subject->setContents([$declarationBlock]);
493469

494-
$result = $subject->getAllValues(null, true);
495-
496-
self::assertSame([$value1, $value2], $result);
497-
}
498-
499-
/**
500-
* @test
501-
*/
502-
public function getAllValuesWithSearchInFunctionArgumentsInNewMethodSignatureReturnsValuesInFunctionArguments(): void
503-
{
504-
$subject = new ConcreteCSSBlockList();
505-
506-
$value1 = new Size(10, 'px');
507-
$value2 = new Size(2, '%');
508-
509-
$declarationBlock = new DeclarationBlock();
510-
$rule = new Rule('margin');
511-
$rule->setValue(new CSSFunction('max', [$value1, $value2]));
512-
$declarationBlock->addRule($rule);
513-
$subject->setContents([$declarationBlock]);
514-
515470
$result = $subject->getAllValues(null, null, true);
516471

517472
self::assertSame([$value1, $value2], $result);

0 commit comments

Comments
 (0)