Skip to content

[TASK] Remove original getAllValues() API #1243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ Please also have a look at our

### Removed

- Passing a string as the first argument to `getAllValues()` is no longer
supported and will not work;
the search pattern should now be passed as the second argument (#1243)
- Passing a Boolean as the second argument to `getAllValues()` is no longer
supported and will not work; the flag for searching in function arguments
should now be passed as the third argument (#1243)
- Remove `__toString()` (#1046)
- Drop magic method forwarding in `OutputFormat` (#898)
- Drop `atRuleArgs()` from the `AtRule` interface (#1141)
Expand Down
32 changes: 6 additions & 26 deletions src/CSSList/CSSBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,26 @@ public function getAllRuleSets(): array
/**
* Returns all `Value` objects found recursively in `Rule`s in the tree.
*
* @param CSSElement|string|null $element
* @param CSSElement|null $element
* This is the `CSSList` or `RuleSet` to start the search from (defaults to the whole document).
* If a string is given, it is used as a rule name filter.
* Passing a string for this parameter is deprecated in version 8.9.0, and will not work from v9.0;
* use the following parameter to pass a rule name filter instead.
* @param string|bool|null $ruleSearchPatternOrSearchInFunctionArguments
* @param string|null $ruleSearchPattern
* This allows filtering rules by property name
* (e.g. if "color" is passed, only `Value`s from `color` properties will be returned,
* or if "font-" is provided, `Value`s from all font rules, like `font-size`, and including `font` itself,
* will be returned).
* If a Boolean is provided, it is treated as the `$searchInFunctionArguments` argument.
* Passing a Boolean for this parameter is deprecated in version 8.9.0, and will not work from v9.0;
* use the `$searchInFunctionArguments` parameter instead.
* @param bool $searchInFunctionArguments whether to also return Value objects used as Function arguments.
* @param bool $searchInFunctionArguments whether to also return `Value` objects used as `CSSFunction` arguments.
*
* @return array<int, Value>
*
* @see RuleSet->getRules()
*/
public function getAllValues(
$element = null,
$ruleSearchPatternOrSearchInFunctionArguments = null,
?CSSElement $element = null,
?string $ruleSearchPattern = null,
bool $searchInFunctionArguments = false
): array {
if (\is_bool($ruleSearchPatternOrSearchInFunctionArguments)) {
$searchInFunctionArguments = $ruleSearchPatternOrSearchInFunctionArguments;
$searchString = null;
} else {
$searchString = $ruleSearchPatternOrSearchInFunctionArguments;
}

if ($element === null) {
$element = $this;
} elseif (\is_string($element)) {
$searchString = $element;
$element = $this;
}

$result = [];
$this->allValues($element, $result, $searchString, $searchInFunctionArguments);
$this->allValues($element ?? $this, $result, $ruleSearchPattern, $searchInFunctionArguments);
return $result;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function colorParsing(): void
self::assertEmpty($colorRules);
}
}
foreach ($document->getAllValues('color') as $colorValue) {
foreach ($document->getAllValues(null, 'color') as $colorValue) {
self::assertSame('red', $colorValue);
}
self::assertSame(
Expand Down Expand Up @@ -455,15 +455,15 @@ public function functionSyntax(): void
. '.collapser.expanded + * {height: auto;}';
self::assertSame($expected, $document->render());

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

foreach ($document->getAllValues(null, true) as $value) {
foreach ($document->getAllValues(null, null, true) as $value) {
if ($value instanceof Size && !$value->isRelative() && !$value->isColorComponent()) {
$value->setSize($value->getSize() * 2);
}
Expand Down
45 changes: 0 additions & 45 deletions tests/Unit/CSSList/CSSBlockListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,30 +425,6 @@ public function getAllValuesWithSearchStringProvidedReturnsOnlyValuesFromMatchin
$declarationBlock->addRule($rule2);
$subject->setContents([$declarationBlock]);

$result = $subject->getAllValues('font-');

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

/**
* @test
*/
public function getAllValuesWithSearchStringProvidedInNewMethodSignatureReturnsOnlyValuesFromMatchingRules(): void
{
$subject = new ConcreteCSSBlockList();

$value1 = new CSSString('Superfont');
$value2 = new CSSString('aquamarine');

$declarationBlock = new DeclarationBlock();
$rule1 = new Rule('font-family');
$rule1->setValue($value1);
$declarationBlock->addRule($rule1);
$rule2 = new Rule('color');
$rule2->setValue($value2);
$declarationBlock->addRule($rule2);
$subject->setContents([$declarationBlock]);

$result = $subject->getAllValues(null, 'font-');

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

$result = $subject->getAllValues(null, true);

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

/**
* @test
*/
public function getAllValuesWithSearchInFunctionArgumentsInNewMethodSignatureReturnsValuesInFunctionArguments(): void
{
$subject = new ConcreteCSSBlockList();

$value1 = new Size(10, 'px');
$value2 = new Size(2, '%');

$declarationBlock = new DeclarationBlock();
$rule = new Rule('margin');
$rule->setValue(new CSSFunction('max', [$value1, $value2]));
$declarationBlock->addRule($rule);
$subject->setContents([$declarationBlock]);

$result = $subject->getAllValues(null, null, true);

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