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

### Changed

- `RuleSet\RuleContainer` is renamed to `RuleSet\DeclarationList` (#1530)
- Methods like `setRule()` in `RuleSet` and `DeclarationBlock` have been renamed
to `setDeclaration()`, etc. (#1521)
- `Rule\Rule` class is renamed to `Property\Declaration`
Expand All @@ -35,6 +36,8 @@ Please also have a look at our

### Deprecated

- `RuleSet\RuleContainer` is deprecated; use `RuleSet\DeclarationList` instead
(#1530)
- 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
Expand Down
1 change: 1 addition & 0 deletions config/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ parameters:

bootstrapFiles:
- %currentWorkingDirectory%/src/Rule/Rule.php
- %currentWorkingDirectory%/src/RuleSet/RuleContainer.php
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.

We'll need to replace these additional bootstrap file as soon as possible (in a dedicated PR) with something that also works for consumers of our library. At the moment, PHPStan fails to find these aliases within Emogrifier, and other consumers will run into the same problem.

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.

We'll need to replace these additional bootstrap file

Oh. I don't know of a way of doing that.

The aliases allow us to make a minor release using the new class names, with the old class names deprecated. Then they will be dropped in the next major release.

I expected Stan to find the alias files; when I found it didn't, I discoved this means of telling it.

Is there a way of providing some PHPStan config for consumers? Or maybe a 'dev' Composer autoload setting could work?

Copy link
Copy Markdown
Collaborator

@oliverklee oliverklee Feb 17, 2026

Choose a reason for hiding this comment

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

I think we can try these approaches (in this order until one solves the problem):

  1. Add a file autoloading/class-aliases.php (or something similar), move all class aliases there, and add it to autoload.files in composer.json.
  2. Try the TYPO3 class alias loader (in PHP-CSS-Parser, not in Emogrifier, so we know this works for consumers)

Copy link
Copy Markdown
Collaborator Author

@JakeQZ JakeQZ Feb 17, 2026

Choose a reason for hiding this comment

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

🤞

I see there is a branch in Emogrifier that uses the dev branch of PHP-CSS-Parser, but not sure how to experimentally hack Composer's vendor directory. Though maybe if there is a way via Composer to avoid the PHPStan bootstrap settings within PHP-CSS-Parser itself, that may solve the problem for consumers.

Copy link
Copy Markdown
Collaborator

@oliverklee oliverklee Feb 17, 2026

Choose a reason for hiding this comment

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

We can create a PR (or a branch) here in PHP-CSS-Parser and then create a branch in Emogrifier that uses that branch (similar to the PR that uses PHP-CSS-Parser main) and then either run the tests locally or on CI for a PR.

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.

I've just entered #1532 for this and will give it a try.

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.

@JakeQZ This is how I tested this in Emogrifier without having to push to GitHub first: MyIntervals/emogrifier#1570


type_perfect:
no_mixed_property: true
Expand Down
77 changes: 77 additions & 0 deletions src/RuleSet/DeclarationList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace Sabberworm\CSS\RuleSet;

use Sabberworm\CSS\Property\Declaration;

/**
* Represents a CSS item that contains `Declaration`s, defining the methods to manipulate them.
*/
interface DeclarationList
{
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;
}
71 changes: 3 additions & 68 deletions src/RuleSet/RuleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,9 @@

namespace Sabberworm\CSS\RuleSet;

use Sabberworm\CSS\Property\Declaration;
use function Safe\class_alias;

/**
* Represents a CSS item that contains `Declaration`s, defining the methods to manipulate them.
* @deprecated in v9.2, will be removed in v10.0. Use `DeclarationList` instead, which is a direct replacement.
*/
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;
}
class_alias(DeclarationList::class, RuleContainer::class);