Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Please also have a look at our

### Changed

- Methods like `setRule()` in `RuleSet` and `DeclarationBlock` have been renamed
to `setDeclaration()`, etc. (#1521)
- `Rule\Rule` class is renamed to `Property\Declaration`
(#1508, #1512, #1513, #1522)
- `Rule::setRule()` and `getRule()` are replaced with `setPropertyName()` and
Expand All @@ -33,6 +35,8 @@ Please also have a look at our

### Deprecated

- Methods like `setRule()` in `RuleSet` and `DeclarationBlock` are deprecated;
there are direct replacements such as `setDeclaration()` (#1521)
- `Rule\Rule` class is deprecated; `Property\Declaration` is a direct
replacement (#1508)
- `Rule::setRule()` and `getRule()` are deprecated and replaced with
Expand Down
2 changes: 1 addition & 1 deletion src/RuleSet/AtRuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function render(OutputFormat $outputFormat): string
$arguments = ' ' . $arguments;
}
$result .= "@{$this->type}$arguments{$formatter->spaceBeforeOpeningBrace()}{";
$result .= $this->renderRules($outputFormat);
$result .= $this->renderDeclarations($outputFormat);
$result .= '}';
return $result;
}
Expand Down
43 changes: 22 additions & 21 deletions src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class DeclarationBlock implements CSSElement, CSSListItem, Positionable, RuleContainer
{
use CommentContainer;
use LegacyRuleContainerMethods;
use Position;

/**
Expand Down Expand Up @@ -180,65 +181,65 @@ public function getRuleSet(): RuleSet
}

/**
* @see RuleSet::addRule()
* @see RuleSet::addDeclaration()
*/
public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = null): void
public function addDeclaration(Declaration $declarationToAdd, ?Declaration $sibling = null): void
{
$this->ruleSet->addRule($declarationToAdd, $sibling);
$this->ruleSet->addDeclaration($declarationToAdd, $sibling);
}

/**
* @return array<int<0, max>, Declaration>
*
* @see RuleSet::getRules()
* @see RuleSet::getDeclarations()
*/
public function getRules(?string $searchPattern = null): array
public function getDeclarations(?string $searchPattern = null): array
{
return $this->ruleSet->getRules($searchPattern);
return $this->ruleSet->getDeclarations($searchPattern);
}

/**
* @param array<Declaration> $declarations
*
* @see RuleSet::setRules()
* @see RuleSet::setDeclarations()
*/
public function setRules(array $declarations): void
public function setDeclarations(array $declarations): void
{
$this->ruleSet->setRules($declarations);
$this->ruleSet->setDeclarations($declarations);
}

/**
* @return array<string, Declaration>
*
* @see RuleSet::getRulesAssoc()
* @see RuleSet::getDeclarationsAssociative()
*/
public function getRulesAssoc(?string $searchPattern = null): array
public function getDeclarationsAssociative(?string $searchPattern = null): array
{
return $this->ruleSet->getRulesAssoc($searchPattern);
return $this->ruleSet->getDeclarationsAssociative($searchPattern);
}

/**
* @see RuleSet::removeRule()
* @see RuleSet::removeDeclaration()
*/
public function removeRule(Declaration $declarationToRemove): void
public function removeDeclaration(Declaration $declarationToRemove): void
{
$this->ruleSet->removeRule($declarationToRemove);
$this->ruleSet->removeDeclaration($declarationToRemove);
}

/**
* @see RuleSet::removeMatchingRules()
* @see RuleSet::removeMatchingDeclarations()
*/
public function removeMatchingRules(string $searchPattern): void
public function removeMatchingDeclarations(string $searchPattern): void
{
$this->ruleSet->removeMatchingRules($searchPattern);
$this->ruleSet->removeMatchingDeclarations($searchPattern);
}

/**
* @see RuleSet::removeAllRules()
* @see RuleSet::removeAllDeclarations()
*/
public function removeAllRules(): void
public function removeAllDeclarations(): void
{
$this->ruleSet->removeAllRules();
$this->ruleSet->removeAllDeclarations();
}

/**
Expand Down
75 changes: 75 additions & 0 deletions src/RuleSet/LegacyRuleContainerMethods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace Sabberworm\CSS\RuleSet;

use Sabberworm\CSS\Property\Declaration;

/**
* Provides a mapping of the deprecated methods in a `RuleContainer` to their renamed replacements.
*/
trait LegacyRuleContainerMethods
{
/**
* @deprecated in v9.2, will be removed in v10.0; use `addDeclaration()` instead.
*/
public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = null): void
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these methods should get an @deprecated annotation stating since which version they are deprecated and in which version they will be removed (like in RuleContainer).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered about this, as I had marked the trait as @internal, but the methods are public and implemented in the classes using the trait, and this would be the only place to see the deprecation notice other than in the interface.

I've added the deprecation notices into the trait.

Should the trait nonetheless be marked as @internal?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the trait should not be @internal. The reason is that IDEs mark usages of @internal methods and classes (so that the devs know that they should switch to something else), but probably not if only the trait it @internal.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed @internal and also added a description for the trait.

{
$this->addDeclaration($declarationToAdd, $sibling);
}

/**
* @deprecated in v9.2, will be removed in v10.0; use `removeDeclaration()` instead.
*/
public function removeRule(Declaration $declarationToRemove): void
{
$this->removeDeclaration($declarationToRemove);
}

/**
* @deprecated in v9.2, will be removed in v10.0; use `removeMatchingDeclarations()` instead.
*/
public function removeMatchingRules(string $searchPattern): void
{
$this->removeMatchingDeclarations($searchPattern);
}

/**
* @deprecated in v9.2, will be removed in v10.0; use `removeAllDeclarations()` instead.
*/
public function removeAllRules(): void
{
$this->removeAllDeclarations();
}

/**
* @param array<Declaration> $declarations
*
* @deprecated in v9.2, will be removed in v10.0; use `setDeclarations()` instead.
*/
public function setRules(array $declarations): void
{
$this->setDeclarations($declarations);
}

/**
* @return array<int<0, max>, Declaration>
*
* @deprecated in v9.2, will be removed in v10.0; use `getDeclarations()` instead.
*/
public function getRules(?string $searchPattern = null): array
{
return $this->getDeclarations($searchPattern);
}

/**
* @return array<string, Declaration>
*
* @deprecated in v9.2, will be removed in v10.0; use `getDeclarationsAssociative()` instead.
*/
public function getRulesAssoc(?string $searchPattern = null): array
{
return $this->getDeclarationsAssociative($searchPattern);
}
}
41 changes: 41 additions & 0 deletions src/RuleSet/RuleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,67 @@
*/
interface RuleContainer
{
public function addDeclaration(Declaration $declarationToAdd, ?Declaration $sibling = null): void;

public function removeDeclaration(Declaration $declarationToRemove): void;

public function removeMatchingDeclarations(string $searchPattern): void;

public function removeAllDeclarations(): void;

/**
* @param array<Declaration> $declarations
*/
public function setDeclarations(array $declarations): void;

/**
* @return array<int<0, max>, Declaration>
*/
public function getDeclarations(?string $searchPattern = null): array;

/**
* @return array<string, Declaration>
*/
public function getDeclarationsAssociative(?string $searchPattern = null): array;

/**
* @deprecated in v9.2, will be removed in v10.0; use `addDeclaration()` instead.
*/
public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = null): void;

/**
* @deprecated in v9.2, will be removed in v10.0; use `removeDeclaration()` instead.
*/
public function removeRule(Declaration $declarationToRemove): void;

/**
* @deprecated in v9.2, will be removed in v10.0; use `removeMatchingDeclarations()` instead.
*/
public function removeMatchingRules(string $searchPattern): void;

/**
* @deprecated in v9.2, will be removed in v10.0; use `removeAllDeclarations()` instead.
*/
public function removeAllRules(): void;

/**
* @param array<Declaration> $declarations
*
* @deprecated in v9.2, will be removed in v10.0; use `setDeclarations()` instead.
*/
public function setRules(array $declarations): void;

/**
* @return array<int<0, max>, Declaration>
*
* @deprecated in v9.2, will be removed in v10.0; use `getDeclarations()` instead.
*/
public function getRules(?string $searchPattern = null): array;

/**
* @return array<string, Declaration>
*
* @deprecated in v9.2, will be removed in v10.0; use `getDeclarationsAssociative()` instead.
*/
public function getRulesAssoc(?string $searchPattern = null): array;
}
Loading