From c19b00869426c21dd3574e16a9f4d846cd7b17fb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 11:27:47 +0000 Subject: [PATCH 01/63] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 951992d2..88121e21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -47,7 +47,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -103,7 +103,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 From 724b654aefdce2fc4aa37092804422b78763e347 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 18 Jan 2024 08:49:16 +0000 Subject: [PATCH 02/63] Bump actions/cache from 3 to 4 Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88121e21..b23f7449 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: run: composer config --global --list - name: Cache dependencies installed with composer - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/composer key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }} @@ -116,7 +116,7 @@ jobs: run: composer config --global --list - name: Cache dependencies installed with composer - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/composer key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }} From 759fdfa8066ad204676f6bd3fc59edc5a907be13 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Fri, 19 Jan 2024 19:33:29 +0100 Subject: [PATCH 03/63] [TASK] Prepare the 8.5.0 release I have compiled the changes that seemed relevant from the git history. --- CHANGELOG.md | 29 ++++++++++++++++++++++++++++- composer.json | 5 +++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a23fd0e6..ac0f3082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,31 @@ -# Revision History +# Changelog + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](https://semver.org/). + +## x.y.z + +### Added + +### Changed + +### Deprecated + +### Removed + +### Fixed + +## 8.4.1 + +### Added + +- Add more unit tests + +### Fixed + +- Retain CSSList and Rule comments when rendering CSS (#351) +- Replace invalid `turns` unit with `turn` (#350) +- Also allow string values for rules ## 8.4.0 diff --git a/composer.json b/composer.json index a1f5677b..6b7c9607 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,11 @@ "Sabberworm\\CSS\\Tests\\": "tests/" } }, + "extra": { + "branch-alias": { + "dev-master": "9.0.x-dev" + } + }, "scripts": { "ci": [ "@ci:static" From 6d4c502b41aedc01cd9561a0aa61027ea86dc895 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sat, 27 Jan 2024 20:59:33 +0100 Subject: [PATCH 04/63] Bump to 8.5.0 and add more changes mentioned in review --- CHANGELOG.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac0f3082..c70ef0a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,17 +15,21 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed -## 8.4.1 +## 8.5.0 ### Added -- Add more unit tests +- Add a method to get an import's media queries (#384) +- Add more unit tests (#381, #382) ### Fixed - Retain CSSList and Rule comments when rendering CSS (#351) - Replace invalid `turns` unit with `turn` (#350) -- Also allow string values for rules +- Also allow string values for rules (#348) +- Fix invalid calc parsing (#169) +- Handle scientific notation when parsing sizes (#179) +- Fix PHP 8.1 compatibility in `ParserState::strsplit()` (#344) ## 8.4.0 From 9648ced8f02cf16de6c7d1041c33e900e905c8d2 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 1 Feb 2024 19:50:57 +0100 Subject: [PATCH 05/63] [TASK] Drop support for PHP < 7.2 (#420) --- .github/workflows/ci.yml | 4 ++-- CHANGELOG.md | 2 ++ composer.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b23f7449..0b1d4bae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - php-version: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php-version: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] steps: - name: Checkout @@ -39,7 +39,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ '5.6', '7.0', '7.1', '7.2', '7.3' ] + php-version: [ '7.2', '7.3' ] coverage: [ 'none' ] include: - php-version: '7.4' diff --git a/CHANGELOG.md b/CHANGELOG.md index c70ef0a1..7d8aae4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Removed +- Drop support for PHP < 7.2 (#420) + ### Fixed ## 8.5.0 diff --git a/composer.json b/composer.json index 6b7c9607..1bfad6f6 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=5.6.20", + "php": ">=7.2.0", "ext-iconv": "*" }, "require-dev": { From a89395c5764885ca74c111e3fcef91b1dfbb50f1 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Fri, 2 Feb 2024 17:27:55 +0100 Subject: [PATCH 06/63] [TASK] Sync the PHPUnit configuration file version with the package (#423) --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 5f3dd458..62ad5006 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"> tests From 4bd764ea45f18fc5a38efe12341a374933c0a3fb Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Fri, 2 Feb 2024 17:28:10 +0100 Subject: [PATCH 07/63] [TASK] Add return types to `setUp()` in tests (#425) This is a blocker for the upgrade to PHPUnit 8. --- tests/CSSList/DocumentTest.php | 2 +- tests/CSSList/KeyFrameTest.php | 2 +- tests/OutputFormatTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/CSSList/DocumentTest.php b/tests/CSSList/DocumentTest.php index a727400b..8c0fffdf 100644 --- a/tests/CSSList/DocumentTest.php +++ b/tests/CSSList/DocumentTest.php @@ -18,7 +18,7 @@ class DocumentTest extends TestCase */ private $subject; - protected function setUp() + protected function setUp(): void { $this->subject = new Document(); } diff --git a/tests/CSSList/KeyFrameTest.php b/tests/CSSList/KeyFrameTest.php index 080d5f94..b8620eb4 100644 --- a/tests/CSSList/KeyFrameTest.php +++ b/tests/CSSList/KeyFrameTest.php @@ -18,7 +18,7 @@ class KeyFrameTest extends TestCase */ protected $subject; - protected function setUp() + protected function setUp(): void { $this->subject = new KeyFrame(); } diff --git a/tests/OutputFormatTest.php b/tests/OutputFormatTest.php index 0de39123..02d4ee93 100644 --- a/tests/OutputFormatTest.php +++ b/tests/OutputFormatTest.php @@ -43,7 +43,7 @@ class OutputFormatTest extends TestCase */ private $oDocument; - protected function setUp() + protected function setUp(): void { $this->oParser = new Parser(self::TEST_CSS); $this->oDocument = $this->oParser->parse(); From 73b034476ab372e5bf59ddaae2ffb31d1a44fd23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:32:00 +0100 Subject: [PATCH 08/63] [TASK] Update phpunit/phpunit requirement from ^5.7.27 to ^8.5.36 (#424) Updates the requirements on [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) to permit the latest version. - [Changelog](https://github.com/sebastianbergmann/phpunit/blob/8.5.36/ChangeLog-8.5.md) - [Commits](https://github.com/sebastianbergmann/phpunit/compare/5.7.27...8.5.36) --- updated-dependencies: - dependency-name: phpunit/phpunit dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- phpunit.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1bfad6f6..fdae1fab 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "ext-iconv": "*" }, "require-dev": { - "phpunit/phpunit": "^5.7.27", + "phpunit/phpunit": "^8.5.36", "codacy/coverage": "^1.4.3" }, "suggest": { diff --git a/phpunit.xml b/phpunit.xml index 62ad5006..dad27809 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"> tests From af5a176936289ad5026a91a188e9f72ea8f335e5 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sat, 3 Feb 2024 01:23:37 +0100 Subject: [PATCH 09/63] [TASK] Update the development tools (#421) --- .github/workflows/ci.yml | 2 +- .phive/phars.xml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b1d4bae..90354c79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -130,7 +130,7 @@ jobs: - name: Install development tools run: | - phive --no-progress install --trust-gpg-keys BBAB5DF0A0D6672989CF1869E82B2FB314E9906E,A972B9ABB95D0B760B51442231C7E470E2138192,D32680D5957DC7116BE29C14CF1A108D0E7AE720 + phive --no-progress install --trust-gpg-keys BBAB5DF0A0D6672989CF1869E82B2FB314E9906E,95DE904AB800754A11D80B605E6DDE998AB73B8E,CA7C2C7A30C8E8E1274A847651C67305FFC2E5C0 - name: Run Command run: composer ci:php:${{ matrix.command }} diff --git a/.phive/phars.xml b/.phive/phars.xml index d353fbf9..5a541c39 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,7 +1,7 @@ - - - - + + + + From d518539ee085dc2179a4ef594f516cd6f9662131 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sat, 3 Feb 2024 01:31:49 +0100 Subject: [PATCH 10/63] [TASK] Also PHP-lint the code with PHP 8.3 (#426) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90354c79..6bfafcbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - php-version: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php-version: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] steps: - name: Checkout From 9d6c1d86fe8debd3d71c0d36f7a90430e6e55885 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sat, 3 Feb 2024 20:16:51 +0100 Subject: [PATCH 11/63] [TASK] Add the new maintainers to the `composer.json` (#428) --- composer.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/composer.json b/composer.json index fdae1fab..3852633d 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,14 @@ "authors": [ { "name": "Raphael Schweikert" + }, + { + "name": "Oliver Klee", + "email": "github@oliverklee.de" + }, + { + "name": "Jake Hotson", + "email": "jake.github@qzdesign.co.uk" } ], "require": { From e78a796e08705390bbf9e36d0fd7c950356e46ed Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 4 Feb 2024 01:07:21 +0100 Subject: [PATCH 12/63] [BUGFIX] Git-ignore the PHPUnit result cache (#429) The corresponding file gets created by more recent versions of PHPUnit. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c1747f26..acf0d9d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.phive/* /.php-cs-fixer.cache /.php_cs.cache +/.phpunit.result.cache /composer.lock /phpstan.neon /vendor/ From a2282d63ff7851cb0c5e553d38ac32e4376406d7 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 4 Feb 2024 02:14:28 +0100 Subject: [PATCH 13/63] [TASK] Make the testcases final (#435) This helps communicate that the testcases are not intended to be subclassed. Fixes #431 --- tests/CSSList/AtRuleBlockListTest.php | 2 +- tests/CSSList/DocumentTest.php | 2 +- tests/CSSList/KeyFrameTest.php | 2 +- tests/Comment/CommentTest.php | 2 +- tests/OutputFormatTest.php | 2 +- tests/ParserTest.php | 2 +- tests/RuleSet/DeclarationBlockTest.php | 2 +- tests/RuleSet/LenientParsingTest.php | 2 +- tests/Value/CalcRuleValueListTest.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/CSSList/AtRuleBlockListTest.php b/tests/CSSList/AtRuleBlockListTest.php index 48e6e578..a90aa9b2 100644 --- a/tests/CSSList/AtRuleBlockListTest.php +++ b/tests/CSSList/AtRuleBlockListTest.php @@ -11,7 +11,7 @@ /** * @covers \Sabberworm\CSS\CSSList\AtRuleBlockList */ -class AtRuleBlockListTest extends TestCase +final class AtRuleBlockListTest extends TestCase { /** * @test diff --git a/tests/CSSList/DocumentTest.php b/tests/CSSList/DocumentTest.php index 8c0fffdf..36d29057 100644 --- a/tests/CSSList/DocumentTest.php +++ b/tests/CSSList/DocumentTest.php @@ -11,7 +11,7 @@ /** * @covers \Sabberworm\CSS\CSSList\Document */ -class DocumentTest extends TestCase +final class DocumentTest extends TestCase { /** * @var Document diff --git a/tests/CSSList/KeyFrameTest.php b/tests/CSSList/KeyFrameTest.php index b8620eb4..293e4f3a 100644 --- a/tests/CSSList/KeyFrameTest.php +++ b/tests/CSSList/KeyFrameTest.php @@ -11,7 +11,7 @@ /** * @covers \Sabberworm\CSS\CSSList\KeyFrame */ -class KeyFrameTest extends TestCase +final class KeyFrameTest extends TestCase { /** * @var KeyFrame diff --git a/tests/Comment/CommentTest.php b/tests/Comment/CommentTest.php index 29385f01..ea1c8782 100644 --- a/tests/Comment/CommentTest.php +++ b/tests/Comment/CommentTest.php @@ -14,7 +14,7 @@ * @covers \Sabberworm\CSS\OutputFormat * @covers \Sabberworm\CSS\OutputFormatter */ -class CommentTest extends TestCase +final class CommentTest extends TestCase { /** * @test diff --git a/tests/OutputFormatTest.php b/tests/OutputFormatTest.php index 02d4ee93..dc991cab 100644 --- a/tests/OutputFormatTest.php +++ b/tests/OutputFormatTest.php @@ -11,7 +11,7 @@ /** * @covers \Sabberworm\CSS\OutputFormat */ -class OutputFormatTest extends TestCase +final class OutputFormatTest extends TestCase { /** * @var string diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 74449ee2..c5ddeb44 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -35,7 +35,7 @@ * @covers \Sabberworm\CSS\Value\Size::parse * @covers \Sabberworm\CSS\Value\URL::parse */ -class ParserTest extends TestCase +final class ParserTest extends TestCase { /** * @test diff --git a/tests/RuleSet/DeclarationBlockTest.php b/tests/RuleSet/DeclarationBlockTest.php index 49526952..31d31df5 100644 --- a/tests/RuleSet/DeclarationBlockTest.php +++ b/tests/RuleSet/DeclarationBlockTest.php @@ -10,7 +10,7 @@ /** * @covers \Sabberworm\CSS\RuleSet\DeclarationBlock */ -class DeclarationBlockTest extends TestCase +final class DeclarationBlockTest extends TestCase { /** * @param string $sCss diff --git a/tests/RuleSet/LenientParsingTest.php b/tests/RuleSet/LenientParsingTest.php index 5f5f224a..54d63e5b 100644 --- a/tests/RuleSet/LenientParsingTest.php +++ b/tests/RuleSet/LenientParsingTest.php @@ -19,7 +19,7 @@ * @covers \Sabberworm\CSS\Value\Size::parse * @covers \Sabberworm\CSS\Value\URL::parse */ -class LenientParsingTest extends TestCase +final class LenientParsingTest extends TestCase { /** * @test diff --git a/tests/Value/CalcRuleValueListTest.php b/tests/Value/CalcRuleValueListTest.php index 0a2c5304..0ce279fd 100644 --- a/tests/Value/CalcRuleValueListTest.php +++ b/tests/Value/CalcRuleValueListTest.php @@ -9,7 +9,7 @@ /** * @covers \Sabberworm\CSS\Value\CalcRuleValueList */ -class CalcRuleValueListTest extends TestCase +final class CalcRuleValueListTest extends TestCase { /** * @test From 084e3761afa06b3c4b8ec636b516a8d58e597604 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 4 Feb 2024 02:27:50 +0100 Subject: [PATCH 14/63] [TASK] Configure PHPUnit some more (#436) - make things more strict - stop caching the result (as we don't need this at the moment) - make things more colorful --- phpunit.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index dad27809..1060f329 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,12 @@ + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd" + beStrictAboutChangesToGlobalState="true" + beStrictAboutCoversAnnotation="true" + cacheResult="false" + colors="true" + forceCoversAnnotation="true" +> tests From 22992963d2b1b839ac3b04831bd7e2393cd86284 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 4 Feb 2024 02:40:58 +0100 Subject: [PATCH 15/63] [TASK] Move PHPStan from PHIVE to Composer (#438) This allows us to have PHPStan extensions, e.g., for PHPUnit. --- .github/workflows/ci.yml | 2 +- .phive/phars.xml | 1 - composer.json | 10 ++++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bfafcbe..9825c72f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -130,7 +130,7 @@ jobs: - name: Install development tools run: | - phive --no-progress install --trust-gpg-keys BBAB5DF0A0D6672989CF1869E82B2FB314E9906E,95DE904AB800754A11D80B605E6DDE998AB73B8E,CA7C2C7A30C8E8E1274A847651C67305FFC2E5C0 + phive --no-progress install --trust-gpg-keys BBAB5DF0A0D6672989CF1869E82B2FB314E9906E,95DE904AB800754A11D80B605E6DDE998AB73B8E - name: Run Command run: composer ci:php:${{ matrix.command }} diff --git a/.phive/phars.xml b/.phive/phars.xml index 5a541c39..52fc28a2 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -3,5 +3,4 @@ - diff --git a/composer.json b/composer.json index 3852633d..39cf75f0 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ }, "require-dev": { "phpunit/phpunit": "^8.5.36", - "codacy/coverage": "^1.4.3" + "codacy/coverage": "^1.4.3", + "phpstan/phpstan": "^1.10.57" }, "suggest": { "ext-mbstring": "for parsing UTF-8 CSS" @@ -38,6 +39,11 @@ "Sabberworm\\CSS\\": "src/" } }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } + }, "autoload-dev": { "psr-4": { "Sabberworm\\CSS\\Tests\\": "tests/" @@ -54,7 +60,7 @@ ], "ci:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots bin src tests", "ci:php:sniffer": "@php ./.phive/phpcs.phar --standard=config/phpcs.xml bin src tests", - "ci:php:stan": "@php ./.phive/phpstan.phar --configuration=config/phpstan.neon", + "ci:php:stan": "phpstan --no-progress --configuration=config/phpstan.neon", "ci:static": [ "@ci:php:fixer", "@ci:php:sniffer", From e9eb9372e5dbf0ea78ce6a31c80cb138b4a94bdf Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 4 Feb 2024 02:42:50 +0100 Subject: [PATCH 16/63] [TASK] Simplify the configuration for the static analysis CI job (#439) --- .github/workflows/ci.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9825c72f..35eca248 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,13 +93,12 @@ jobs: strategy: fail-fast: false matrix: - include: - - command: sniffer - php-version: '7.4' - - command: fixer - php-version: '7.4' - - command: stan - php-version: '7.4' + command: + - sniffer + - fixer + - stan + php-version: + - '7.4' steps: - name: Checkout From b0c1403cf458110142a375119647726aa0a24fb3 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 4 Feb 2024 02:44:47 +0100 Subject: [PATCH 17/63] [CLEANUP] Autoformat the code (#440) Autoformat the code with the default PhpStorm settings (and re-run `composer fix:php` to minimize formatting-related changes when code is changed and autoformatted. --- src/OutputFormatter.php | 1 + src/Value/Value.php | 6 +++--- tests/Comment/CommentTest.php | 14 +++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/OutputFormatter.php b/src/OutputFormatter.php index 7418494c..501d15da 100644 --- a/src/OutputFormatter.php +++ b/src/OutputFormatter.php @@ -215,6 +215,7 @@ public function removeLastSemicolon($sString) /** * * @param array $aComments + * * @return string */ public function comments(Commentable $oCommentable) diff --git a/src/Value/Value.php b/src/Value/Value.php index a920396b..ce6d5790 100644 --- a/src/Value/Value.php +++ b/src/Value/Value.php @@ -43,9 +43,9 @@ public static function parseValue(ParserState $oParserState, array $aListDelimit //Build a list of delimiters and parsed values while ( !($oParserState->comes('}') || $oParserState->comes(';') || $oParserState->comes('!') - || $oParserState->comes(')') - || $oParserState->comes('\\') - || $oParserState->isEnd()) + || $oParserState->comes(')') + || $oParserState->comes('\\') + || $oParserState->isEnd()) ) { if (count($aStack) > 0) { $bFoundDelimiter = false; diff --git a/tests/Comment/CommentTest.php b/tests/Comment/CommentTest.php index ea1c8782..d26da963 100644 --- a/tests/Comment/CommentTest.php +++ b/tests/Comment/CommentTest.php @@ -140,11 +140,11 @@ public function keepCommentsInOutput() ', $oCss->render(OutputFormat::createPretty())); self::assertSame( '/** Number 11 **//**' . "\n" - . ' * Comments' . "\n" - . ' *//* Hell */@import url("some/url.css") screen;' - . '/* Number 4 *//* Number 5 */.foo,#bar{' - . '/* Number 6 */background-color:#000;}@media screen{' - . '/** Number 10 **/#foo.bar{/** Number 10b **/position:absolute;}}', + . ' * Comments' . "\n" + . ' *//* Hell */@import url("some/url.css") screen;' + . '/* Number 4 *//* Number 5 */.foo,#bar{' + . '/* Number 6 */background-color:#000;}@media screen{' + . '/** Number 10 **/#foo.bar{/** Number 10b **/position:absolute;}}', $oCss->render(OutputFormat::createCompact()->setRenderComments(true)) ); } @@ -170,8 +170,8 @@ public function stripCommentsFromOutput() ', $oCss->render(OutputFormat::createPretty()->setRenderComments(false))); self::assertSame( '@import url("some/url.css") screen;' - . '.foo,#bar{background-color:#000;}' - . '@media screen{#foo.bar{position:absolute;}}', + . '.foo,#bar{background-color:#000;}' + . '@media screen{#foo.bar{position:absolute;}}', $oCss->render(OutputFormat::createCompact()) ); } From 3d7924f4319571d2831cf0bda383ce1eaa88f1eb Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 4 Feb 2024 10:20:31 +0100 Subject: [PATCH 18/63] [TASK] Add some Composer settings (#441) - prefer packages over Git - sort the dependencies Also actually sort the dependencies. --- composer.json | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 39cf75f0..eac8402e 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,9 @@ "ext-iconv": "*" }, "require-dev": { - "phpunit/phpunit": "^8.5.36", "codacy/coverage": "^1.4.3", - "phpstan/phpstan": "^1.10.57" + "phpstan/phpstan": "^1.10.57", + "phpunit/phpunit": "^8.5.36" }, "suggest": { "ext-mbstring": "for parsing UTF-8 CSS" @@ -39,16 +39,20 @@ "Sabberworm\\CSS\\": "src/" } }, - "config": { - "allow-plugins": { - "phpstan/extension-installer": true - } - }, "autoload-dev": { "psr-4": { "Sabberworm\\CSS\\Tests\\": "tests/" } }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + }, + "preferred-install": { + "*": "dist" + }, + "sort-packages": true + }, "extra": { "branch-alias": { "dev-master": "9.0.x-dev" From 273490cbb2c68aa93acca8853615e023ebfd98f6 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 5 Feb 2024 03:16:48 +0100 Subject: [PATCH 19/63] [BUGFIX] Avoid double CI runs for pull requests (#437) --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35eca248..7ac1902a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,10 @@ # https://help.github.com/en/categories/automating-your-workflow-with-github-actions on: - pull_request: push: + branches: + - master + pull_request: schedule: - cron: '3 3 * * 1' From 49df8ddb02cef3405ac0cbdb5ad6c001dca63ec6 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 5 Feb 2024 03:41:25 +0100 Subject: [PATCH 20/63] [TASK] Make the data providers static (#443) Newer versions of PHPUnit require this, and we might as well do this now. Closes #414 --- tests/CSSList/AtRuleBlockListTest.php | 2 +- tests/CSSList/DocumentTest.php | 2 +- tests/RuleSet/DeclarationBlockTest.php | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/CSSList/AtRuleBlockListTest.php b/tests/CSSList/AtRuleBlockListTest.php index a90aa9b2..cc234ce6 100644 --- a/tests/CSSList/AtRuleBlockListTest.php +++ b/tests/CSSList/AtRuleBlockListTest.php @@ -46,7 +46,7 @@ public function implementsCommentable() /** * @return array> */ - public function mediaRuleDataProvider() + public static function mediaRuleDataProvider() { return [ 'without spaces around arguments' => ['@media(min-width: 768px){.class{color:red}}'], diff --git a/tests/CSSList/DocumentTest.php b/tests/CSSList/DocumentTest.php index 36d29057..a052e449 100644 --- a/tests/CSSList/DocumentTest.php +++ b/tests/CSSList/DocumentTest.php @@ -50,7 +50,7 @@ public function getContentsInitiallyReturnsEmptyArray() /** * @return array>> */ - public function contentsDataProvider() + public static function contentsDataProvider() { return [ 'empty array' => [[]], diff --git a/tests/RuleSet/DeclarationBlockTest.php b/tests/RuleSet/DeclarationBlockTest.php index 31d31df5..27c6615f 100644 --- a/tests/RuleSet/DeclarationBlockTest.php +++ b/tests/RuleSet/DeclarationBlockTest.php @@ -33,7 +33,7 @@ public function expandBorderShorthand($sCss, $sExpected) /** * @return array> */ - public function expandBorderShorthandProvider() + public static function expandBorderShorthandProvider() { return [ ['body{ border: 2px solid #000 }', 'body {border-width: 2px;border-style: solid;border-color: #000;}'], @@ -66,7 +66,7 @@ public function expandFontShorthand($sCss, $sExpected) /** * @return array> */ - public function expandFontShorthandProvider() + public static function expandFontShorthandProvider() { return [ [ @@ -122,7 +122,7 @@ public function expandBackgroundShorthand($sCss, $sExpected) /** * @return array> */ - public function expandBackgroundShorthandProvider() + public static function expandBackgroundShorthandProvider() { return [ ['body {border: 1px;}', 'body {border: 1px;}'], @@ -175,7 +175,7 @@ public function expandDimensionsShorthand($sCss, $sExpected) /** * @return array> */ - public function expandDimensionsShorthandProvider() + public static function expandDimensionsShorthandProvider() { return [ ['body {border: 1px;}', 'body {border: 1px;}'], @@ -213,7 +213,7 @@ public function createBorderShorthand($sCss, $sExpected) /** * @return array> */ - public function createBorderShorthandProvider() + public static function createBorderShorthandProvider() { return [ ['body {border-width: 2px;border-style: solid;border-color: #000;}', 'body {border: 2px solid #000;}'], @@ -244,7 +244,7 @@ public function createFontShorthand($sCss, $sExpected) /** * @return array> */ - public function createFontShorthandProvider() + public static function createFontShorthandProvider() { return [ ['body {font-size: 12px; font-family: serif}', 'body {font: 12px serif;}'], @@ -287,7 +287,7 @@ public function createDimensionsShorthand($sCss, $sExpected) /** * @return array> */ - public function createDimensionsShorthandProvider() + public static function createDimensionsShorthandProvider() { return [ ['body {border: 1px;}', 'body {border: 1px;}'], @@ -325,7 +325,7 @@ public function createBackgroundShorthand($sCss, $sExpected) /** * @return array> */ - public function createBackgroundShorthandProvider() + public static function createBackgroundShorthandProvider() { return [ ['body {border: 1px;}', 'body {border: 1px;}'], From 83ccf6e853a06d7bd526bd629a68124c3962db22 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 6 Feb 2024 00:16:32 +0100 Subject: [PATCH 21/63] [TASK] Move the coverage generation to a separate CI workflow (#427) --- .github/workflows/ci.yml | 15 ++------ .github/workflows/codecoverage.yml | 57 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/codecoverage.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ac1902a..88ba1dc4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,10 +42,6 @@ jobs: fail-fast: false matrix: php-version: [ '7.2', '7.3' ] - coverage: [ 'none' ] - include: - - php-version: '7.4' - coverage: xdebug steps: - name: Checkout @@ -57,7 +53,7 @@ jobs: php-version: ${{ matrix.php-version }} ini-values: error_reporting=E_ALL tools: composer:v2 - coverage: "${{ matrix.coverage }}" + coverage: none - name: Show the Composer configuration run: composer config --global --list @@ -76,14 +72,7 @@ jobs: composer show; - name: Run Tests - run: ./vendor/bin/phpunit --coverage-clover build/coverage/xml - - - name: Upload coverage results to Codacy - env: - CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} - if: "${{ matrix.coverage != 'none' && env.CODACY_PROJECT_TOKEN != '' }}" - run: | - ./vendor/bin/codacycoverage clover build/coverage/xml + run: ./vendor/bin/phpunit static-analysis: name: Static Analysis diff --git a/.github/workflows/codecoverage.yml b/.github/workflows/codecoverage.yml new file mode 100644 index 00000000..76568630 --- /dev/null +++ b/.github/workflows/codecoverage.yml @@ -0,0 +1,57 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +on: + push: + branches: + - master + pull_request: + +name: Code coverage + +jobs: + code-coverage: + name: Code coverage + + runs-on: ubuntu-22.04 + + strategy: + matrix: + php-version: [ '7.4' ] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + ini-values: error_reporting=E_ALL + tools: composer:v2 + coverage: xdebug + + - name: Show the Composer configuration + run: composer config --global --list + + - name: Cache dependencies installed with composer + uses: actions/cache@v4 + with: + path: ~/.cache/composer + key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php-version }}-composer- + + - name: Install Composer dependencies + run: | + composer update --with-dependencies --no-progress; + composer show; + + - name: Run Tests + run: ./vendor/bin/phpunit --coverage-clover build/coverage/xml + + - name: Upload coverage results to Codacy + env: + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} + if: "${{ env.CODACY_PROJECT_TOKEN != '' }}" + run: | + ./vendor/bin/codacycoverage clover build/coverage/xml From daf4cdd98298255f4bc722d2cd006472f05d94e7 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 6 Feb 2024 00:35:07 +0100 Subject: [PATCH 22/63] [FEATURE] Add a PHPUnit-specific extension to PHPStan (#444) This enables PHPStan to understand certain PHPUnit-specific constructs. --- composer.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/composer.json b/composer.json index eac8402e..3d6cbdd6 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,9 @@ }, "require-dev": { "codacy/coverage": "^1.4.3", + "phpstan/extension-installer": "^1.3.1", "phpstan/phpstan": "^1.10.57", + "phpstan/phpstan-phpunit": "^1.3.15", "phpunit/phpunit": "^8.5.36" }, "suggest": { From a06828763ff5ba68ed974f2f60633d81725c2493 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 6 Feb 2024 00:48:27 +0100 Subject: [PATCH 23/63] [BUGFIX] Use the Composer-installed PHPStan for creating the baseline (#445) Followup to #438 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3d6cbdd6..0085e722 100644 --- a/composer.json +++ b/composer.json @@ -78,7 +78,7 @@ ], "fix:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix bin src tests", "fix:php:sniffer": "@php ./.phive/phpcbf.phar --standard=config/phpcs.xml bin src tests", - "phpstan:baseline": "@php ./.phive/phpstan.phar --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon" + "phpstan:baseline": "phpstan --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon" }, "scripts-descriptions": { "ci": "Runs all dynamic and static code checks (i.e. currently, only the static checks).", From f9cae12ef663943e7007ed64508b254eec2f1465 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 6 Feb 2024 00:50:00 +0100 Subject: [PATCH 24/63] [TASK] Switch the static analysis CI jobs to PHP 8.3 (#446) This should improve CI performance a bit. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88ba1dc4..4552af5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,7 +89,7 @@ jobs: - fixer - stan php-version: - - '7.4' + - '8.3' steps: - name: Checkout From be537993941c20c92bfb302ba7db2d6601bbcb89 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 6 Feb 2024 00:52:08 +0100 Subject: [PATCH 25/63] [TASK] Run the unit tests up to PHP 8.3 (#447) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4552af5c..e14e81d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ '7.2', '7.3' ] + php-version: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] steps: - name: Checkout From 79f7865977b9ed60efd127c516bc4f799188cf22 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 6 Feb 2024 19:52:15 +0100 Subject: [PATCH 26/63] [CLEANUP] Make variable acces in `DeclarationBlock` more obvious (#448) --- config/phpstan-baseline.neon | 5 ----- src/RuleSet/DeclarationBlock.php | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/config/phpstan-baseline.neon b/config/phpstan-baseline.neon index b730548c..243e36c4 100644 --- a/config/phpstan-baseline.neon +++ b/config/phpstan-baseline.neon @@ -10,11 +10,6 @@ parameters: count: 2 path: ../src/RuleSet/DeclarationBlock.php - - - message: "#^Variable \\$oRule might not be defined\\.$#" - count: 2 - path: ../src/RuleSet/DeclarationBlock.php - - message: "#^Variable \\$oVal might not be defined\\.$#" count: 1 diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index de487bc1..b218bd8c 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -565,6 +565,7 @@ public function expandListStyleShorthand() public function createShorthandProperties(array $aProperties, $sShorthand) { $aRules = $this->getRulesAssoc(); + $oRule = null; $aNewValues = []; foreach ($aProperties as $sProperty) { if (!isset($aRules[$sProperty])) { @@ -585,7 +586,7 @@ public function createShorthandProperties(array $aProperties, $sShorthand) $this->removeRule($sProperty); } } - if (count($aNewValues)) { + if ($aNewValues !== [] && $oRule instanceof Rule) { $oNewRule = new Rule($sShorthand, $oRule->getLineNo(), $oRule->getColNo()); foreach ($aNewValues as $mValue) { $oNewRule->addValue($mValue); From 2cbe0288057ff6b154612263610bf3546f54e792 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 6 Feb 2024 23:31:44 +0100 Subject: [PATCH 27/63] [FEATURE] Add unit tests for the existing `Settings` methods (#449) --- CHANGELOG.md | 2 + tests/SettingsTest.php | 155 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 tests/SettingsTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d8aae4d..1dc542d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Added +- Add more tests (#449) + ### Changed ### Deprecated diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php new file mode 100644 index 00000000..859059a3 --- /dev/null +++ b/tests/SettingsTest.php @@ -0,0 +1,155 @@ +subject = Settings::create(); + } + + /** + * @test + */ + public function createReturnsInstance(): void + { + $settings = Settings::create(); + + self::assertInstanceOf(Settings::class, $settings); + } + + /** + * @test + */ + public function createReturnsANewInstanceForEachCall(): void + { + $settings1 = Settings::create(); + $settings2 = Settings::create(); + + self::assertNotSame($settings1, $settings2); + } + + /** + * @test + */ + public function multibyteSupportByDefaultStateOfMbStringExtension(): void + { + self::assertSame(extension_loaded('mbstring'), $this->subject->bMultibyteSupport); + } + + /** + * @test + */ + public function withMultibyteSupportProvidesFluentInterface(): void + { + self::assertSame($this->subject, $this->subject->withMultibyteSupport()); + } + + /** + * @return array + */ + public static function booleanDataProvider(): array + { + return [ + 'true' => [true], + 'false' => [false], + ]; + } + + /** + * @test + * @dataProvider booleanDataProvider + */ + public function withMultibyteSupportSetsMultibyteSupport(bool $value): void + { + $this->subject->withMultibyteSupport($value); + + self::assertSame($value, $this->subject->bMultibyteSupport); + } + + /** + * @test + */ + public function defaultCharsetByDefaultIsUtf8(): void + { + self::assertSame('utf-8', $this->subject->sDefaultCharset); + } + + /** + * @test + */ + public function withDefaultCharsetProvidesFluentInterface(): void + { + self::assertSame($this->subject, $this->subject->withDefaultCharset('UTF-8')); + } + + /** + * @test + */ + public function withDefaultCharsetSetsDefaultCharset(): void + { + $charset = 'ISO-8859-1'; + $this->subject->withDefaultCharset($charset); + + self::assertSame($charset, $this->subject->sDefaultCharset); + } + + /** + * @test + */ + public function lenientParsingByDefaultIsTrue(): void + { + self::assertTrue($this->subject->bLenientParsing); + } + + /** + * @test + */ + public function withLenientParsingProvidesFluentInterface(): void + { + self::assertSame($this->subject, $this->subject->withLenientParsing()); + } + + /** + * @test + * @dataProvider booleanDataProvider + */ + public function withLenientParsingSetsLenientParsing(bool $value): void + { + $this->subject->withLenientParsing($value); + + self::assertSame($value, $this->subject->bLenientParsing); + } + + /** + * @test + */ + public function beStrictProvidesFluentInterface(): void + { + self::assertSame($this->subject, $this->subject->beStrict()); + } + + /** + * @test + */ + public function beStrictSetsLenientParsingToFalse(): void + { + $this->subject->beStrict(); + + self::assertFalse($this->subject->bLenientParsing); + } +} From 52ff90165804e99491e76291976f1326be3ea235 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 8 Feb 2024 00:32:21 +0100 Subject: [PATCH 28/63] [TASK] Finish the repository move and switch from master to main (#451) --- .github/workflows/ci.yml | 2 +- .github/workflows/codecoverage.yml | 2 +- README.md | 2 +- composer.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e14e81d7..3ffea44c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ on: push: branches: - - master + - main pull_request: schedule: - cron: '3 3 * * 1' diff --git a/.github/workflows/codecoverage.yml b/.github/workflows/codecoverage.yml index 76568630..adcca2ee 100644 --- a/.github/workflows/codecoverage.yml +++ b/.github/workflows/codecoverage.yml @@ -3,7 +3,7 @@ on: push: branches: - - master + - main pull_request: name: Code coverage diff --git a/README.md b/README.md index 90428cbf..00567417 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PHP CSS Parser -[![Build Status](https://github.com/sabberworm/PHP-CSS-Parser/workflows/CI/badge.svg?branch=master)](https://github.com/sabberworm/PHP-CSS-Parser/actions/) +[![Build Status](https://github.com/MyIntervals/PHP-CSS-Parser/workflows/CI/badge.svg?branch=main)](https://github.com/MyIntervals/PHP-CSS-Parser/actions/) A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS. diff --git a/composer.json b/composer.json index 0085e722..aecc41dd 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ }, "extra": { "branch-alias": { - "dev-master": "9.0.x-dev" + "dev-main": "9.0.x-dev" } }, "scripts": { From 8bb6080e6116b7fb030fad94bbfa4dadcb713e24 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 13 Feb 2024 09:57:12 +0100 Subject: [PATCH 29/63] [TASK] Drop PHP_CodeSniffer (#468) This tool is not well-maintained anymore, and it has no PER2 coding standard, which is a blocker for us moving to PER2. PHP-CS-Fixer already has a PER2 coding standard. If we use PHP-CS-Fixer on PER2 and PHP_CodeSniffer on PSR12 (the latest available standard there), both tools would keep overwriting each other's changes endlessly, and they would never agree on the correct formatting. --- .github/workflows/ci.yml | 3 +-- .phive/phars.xml | 2 -- composer.json | 8 +------- config/phpcs.xml | 17 ----------------- 4 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 config/phpcs.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ffea44c..2bdb67c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,6 @@ jobs: fail-fast: false matrix: command: - - sniffer - fixer - stan php-version: @@ -120,7 +119,7 @@ jobs: - name: Install development tools run: | - phive --no-progress install --trust-gpg-keys BBAB5DF0A0D6672989CF1869E82B2FB314E9906E,95DE904AB800754A11D80B605E6DDE998AB73B8E + phive --no-progress install --trust-gpg-keys BBAB5DF0A0D6672989CF1869E82B2FB314E9906E - name: Run Command run: composer ci:php:${{ matrix.command }} diff --git a/.phive/phars.xml b/.phive/phars.xml index 52fc28a2..3d509be9 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,6 +1,4 @@ - - diff --git a/composer.json b/composer.json index aecc41dd..a8e4d70d 100644 --- a/composer.json +++ b/composer.json @@ -65,30 +65,24 @@ "@ci:static" ], "ci:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots bin src tests", - "ci:php:sniffer": "@php ./.phive/phpcs.phar --standard=config/phpcs.xml bin src tests", "ci:php:stan": "phpstan --no-progress --configuration=config/phpstan.neon", "ci:static": [ "@ci:php:fixer", - "@ci:php:sniffer", "@ci:php:stan" ], "fix:php": [ - "@fix:php:fixer", - "@fix:php:sniffer" + "@fix:php:fixer" ], "fix:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix bin src tests", - "fix:php:sniffer": "@php ./.phive/phpcbf.phar --standard=config/phpcs.xml bin src tests", "phpstan:baseline": "phpstan --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon" }, "scripts-descriptions": { "ci": "Runs all dynamic and static code checks (i.e. currently, only the static checks).", "ci:php:fixer": "Checks the code style with PHP CS Fixer.", - "ci:php:sniffer": "Checks the code style with PHP_CodeSniffer.", "ci:php:stan": "Checks the types with PHPStan.", "ci:static": "Runs all static code analysis checks for the code.", "fix:php": "Autofixes all autofixable issues in the PHP code.", "fix:php:fixer": "Fixes autofixable issues found by PHP CS Fixer.", - "fix:php:sniffer": "Fixes autofixable issues found by PHP_CodeSniffer.", "phpstand:baseline": "Updates the PHPStan baseline file to match the code." } } diff --git a/config/phpcs.xml b/config/phpcs.xml deleted file mode 100644 index 14473bb2..00000000 --- a/config/phpcs.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - This standard requires PHP_CodeSniffer >= 3.6.0. - - - - - - - - - - - - - From c00e58829730fcdf66f1ee6354a9927714fa8a60 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 13 Feb 2024 10:26:02 +0100 Subject: [PATCH 30/63] [TASK] Add visibility to all class/interface constants (#470) This is a pre-patch to switching to the PER2 coding standard. --- CHANGELOG.md | 2 ++ src/Parsing/ParserState.php | 2 +- src/Property/AtRule.php | 4 ++-- src/Property/KeyframeSelector.php | 2 +- src/Property/Selector.php | 6 +++--- src/Value/CalcFunction.php | 4 ++-- src/Value/Size.php | 6 +++--- tests/OutputFormatTest.php | 2 +- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dc542d6..eeddf48e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Changed +- Add visibility to all class/interface constants (#469) + ### Deprecated ### Removed diff --git a/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index 7a99f327..b60e0e06 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -10,7 +10,7 @@ class ParserState /** * @var null */ - const EOF = null; + public const EOF = null; /** * @var Settings diff --git a/src/Property/AtRule.php b/src/Property/AtRule.php index 9536ff5e..df09b5fa 100644 --- a/src/Property/AtRule.php +++ b/src/Property/AtRule.php @@ -13,14 +13,14 @@ interface AtRule extends Renderable, Commentable * * @var string */ - const BLOCK_RULES = 'media/document/supports/region-style/font-feature-values'; + public const BLOCK_RULES = 'media/document/supports/region-style/font-feature-values'; /** * … and more font-specific ones (to be used inside font-feature-values) * * @var string */ - const SET_RULES = 'font-face/counter-style/page/swash/styleset/annotation'; + public const SET_RULES = 'font-face/counter-style/page/swash/styleset/annotation'; /** * @return string|null diff --git a/src/Property/KeyframeSelector.php b/src/Property/KeyframeSelector.php index 14ea5ebb..e44df1f9 100644 --- a/src/Property/KeyframeSelector.php +++ b/src/Property/KeyframeSelector.php @@ -9,7 +9,7 @@ class KeyframeSelector extends Selector * * @var string */ - const SELECTOR_VALIDATION_RX = '/ + public const SELECTOR_VALIDATION_RX = '/ ^( (?: [a-zA-Z0-9\x{00A0}-\x{FFFF}_^$|*="\'~\[\]()\-\s\.:#+>]* # any sequence of valid unescaped characters diff --git a/src/Property/Selector.php b/src/Property/Selector.php index 70c9b2fd..4fc734e9 100644 --- a/src/Property/Selector.php +++ b/src/Property/Selector.php @@ -13,7 +13,7 @@ class Selector * * @var string */ - const NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/ + private const NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/ (\.[\w]+) # classes | \[(\w+) # attributes @@ -37,7 +37,7 @@ class Selector * * @var string */ - const ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/ + private const ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/ ((^|[\s\+\>\~]+)[\w]+ # elements | \:{1,2}( # pseudo-elements @@ -50,7 +50,7 @@ class Selector * * @var string */ - const SELECTOR_VALIDATION_RX = '/ + public const SELECTOR_VALIDATION_RX = '/ ^( (?: [a-zA-Z0-9\x{00A0}-\x{FFFF}_^$|*="\'~\[\]()\-\s\.:#+>]* # any sequence of valid unescaped characters diff --git a/src/Value/CalcFunction.php b/src/Value/CalcFunction.php index 5ffd071f..f06d9b7e 100644 --- a/src/Value/CalcFunction.php +++ b/src/Value/CalcFunction.php @@ -11,12 +11,12 @@ class CalcFunction extends CSSFunction /** * @var int */ - const T_OPERAND = 1; + private const T_OPERAND = 1; /** * @var int */ - const T_OPERATOR = 2; + private const T_OPERATOR = 2; /** * @param ParserState $oParserState diff --git a/src/Value/Size.php b/src/Value/Size.php index 36a32381..0ef18e24 100644 --- a/src/Value/Size.php +++ b/src/Value/Size.php @@ -17,17 +17,17 @@ class Size extends PrimitiveValue * * @var array */ - const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem']; + private const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem']; /** * @var array */ - const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr']; + private const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr']; /** * @var array */ - const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz']; + private const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz']; /** * @var array>|null diff --git a/tests/OutputFormatTest.php b/tests/OutputFormatTest.php index dc991cab..66843eae 100644 --- a/tests/OutputFormatTest.php +++ b/tests/OutputFormatTest.php @@ -16,7 +16,7 @@ final class OutputFormatTest extends TestCase /** * @var string */ - const TEST_CSS = << Date: Tue, 13 Feb 2024 12:23:22 +0100 Subject: [PATCH 31/63] [TASK] Switch to the PER2 coding standard (#467) Fixes #442 --- config/php-cs-fixer.php | 16 +++++++++------- src/CSSList/CSSBlockList.php | 2 +- src/OutputFormat.php | 4 +--- src/Parsing/UnexpectedEOFException.php | 4 +--- src/RuleSet/DeclarationBlock.php | 6 +++--- src/Value/Size.php | 8 ++++---- tests/Comment/CommentTest.php | 2 +- tests/RuleSet/DeclarationBlockTest.php | 16 ++++++++-------- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/config/php-cs-fixer.php b/config/php-cs-fixer.php index 88a9a692..76f52077 100644 --- a/config/php-cs-fixer.php +++ b/config/php-cs-fixer.php @@ -8,9 +8,8 @@ ->setRiskyAllowed(true) ->setRules( [ - '@PSR12' => true, - // Disable constant visibility from the PSR12 rule set as this would break compatibility with PHP < 7.1. - 'visibility_required' => ['elements' => ['property', 'method']], + '@PER-CS2.0' => true, + '@PER-CS2.0:risky' => true, '@PHPUnit50Migration:risky' => true, '@PHPUnit52Migration:risky' => true, @@ -18,15 +17,18 @@ '@PHPUnit55Migration:risky' => true, '@PHPUnit56Migration:risky' => true, '@PHPUnit57Migration:risky' => true, + '@PHPUnit60Migration:risky' => true, + '@PHPUnit75Migration:risky' => true, + '@PHPUnit84Migration:risky' => true, 'php_unit_construct' => true, - 'php_unit_dedicate_assert' => ['target' => '5.6'], - 'php_unit_expectation' => ['target' => '5.6'], + 'php_unit_dedicate_assert' => ['target' => 'newest'], + 'php_unit_expectation' => ['target' => 'newest'], 'php_unit_fqcn_annotation' => true, 'php_unit_method_casing' => true, - 'php_unit_mock' => ['target' => '5.5'], + 'php_unit_mock' => ['target' => 'newest'], 'php_unit_mock_short_will_return' => true, - 'php_unit_namespaced' => ['target' => '5.7'], + 'php_unit_namespaced' => ['target' => 'newest'], 'php_unit_set_up_tear_down_visibility' => true, 'php_unit_test_annotation' => ['style' => 'annotation'], 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], diff --git a/src/CSSList/CSSBlockList.php b/src/CSSList/CSSBlockList.php index fce7913e..6b02edfb 100644 --- a/src/CSSList/CSSBlockList.php +++ b/src/CSSList/CSSBlockList.php @@ -113,7 +113,7 @@ protected function allSelectors(array &$aResult, $sSpecificitySearch = null) $sComparator = $aSpecificitySearch[0]; $iTargetSpecificity = $aSpecificitySearch[1]; } - $iTargetSpecificity = (int)$iTargetSpecificity; + $iTargetSpecificity = (int) $iTargetSpecificity; $iSelectorSpecificity = $oSelector->getSpecificity(); $bMatches = false; switch ($sComparator) { diff --git a/src/OutputFormat.php b/src/OutputFormat.php index 96f26e14..9cc2ae4d 100644 --- a/src/OutputFormat.php +++ b/src/OutputFormat.php @@ -165,9 +165,7 @@ class OutputFormat */ private $iIndentationLevel = 0; - public function __construct() - { - } + public function __construct() {} /** * @param string $sName diff --git a/src/Parsing/UnexpectedEOFException.php b/src/Parsing/UnexpectedEOFException.php index 368ec70c..825cc0c4 100644 --- a/src/Parsing/UnexpectedEOFException.php +++ b/src/Parsing/UnexpectedEOFException.php @@ -7,6 +7,4 @@ * * Extends `UnexpectedTokenException` in order to preserve backwards compatibility. */ -class UnexpectedEOFException extends UnexpectedTokenException -{ -} +class UnexpectedEOFException extends UnexpectedTokenException {} diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index b218bd8c..91f5ecef 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -682,9 +682,9 @@ public function createDimensionsShorthand() $aValues[$sPosition] = $aRuleValues; } $oNewRule = new Rule($sProperty, $oRule->getLineNo(), $oRule->getColNo()); - if ((string)$aValues['left'][0] == (string)$aValues['right'][0]) { - if ((string)$aValues['top'][0] == (string)$aValues['bottom'][0]) { - if ((string)$aValues['top'][0] == (string)$aValues['left'][0]) { + if ((string) $aValues['left'][0] == (string) $aValues['right'][0]) { + if ((string) $aValues['top'][0] == (string) $aValues['bottom'][0]) { + if ((string) $aValues['top'][0] == (string) $aValues['left'][0]) { // All 4 sides are equal $oNewRule->addValue($aValues['top']); } else { diff --git a/src/Value/Size.php b/src/Value/Size.php index 0ef18e24..46036f94 100644 --- a/src/Value/Size.php +++ b/src/Value/Size.php @@ -58,7 +58,7 @@ class Size extends PrimitiveValue public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0) { parent::__construct($iLineNo); - $this->fSize = (float)$fSize; + $this->fSize = (float) $fSize; $this->sUnit = $sUnit; $this->bIsColorComponent = $bIsColorComponent; } @@ -103,7 +103,7 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal } } } - return new Size((float)$sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); + return new Size((float) $sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); } /** @@ -150,7 +150,7 @@ public function getUnit() */ public function setSize($fSize) { - $this->fSize = (float)$fSize; + $this->fSize = (float) $fSize; } /** @@ -211,7 +211,7 @@ public function render(OutputFormat $oOutputFormat) { $l = localeconv(); $sPoint = preg_quote($l['decimal_point'], '/'); - $sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string)$this->fSize) + $sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string) $this->fSize) ? preg_replace("/$sPoint?0+$/", "", sprintf("%f", $this->fSize)) : $this->fSize; return preg_replace(["/$sPoint/", "/^(-?)0\./"], ['.', '$1.'], $sSize) . ($this->sUnit === null ? '' : $this->sUnit); diff --git a/tests/Comment/CommentTest.php b/tests/Comment/CommentTest.php index d26da963..7261e9ba 100644 --- a/tests/Comment/CommentTest.php +++ b/tests/Comment/CommentTest.php @@ -91,7 +91,7 @@ public function toStringRendersCommentEnclosedInCommentDelimiters() $subject->setComment($comment); - self::assertSame('/*' . $comment . '*/', (string)$subject); + self::assertSame('/*' . $comment . '*/', (string) $subject); } /** diff --git a/tests/RuleSet/DeclarationBlockTest.php b/tests/RuleSet/DeclarationBlockTest.php index 27c6615f..31537a9b 100644 --- a/tests/RuleSet/DeclarationBlockTest.php +++ b/tests/RuleSet/DeclarationBlockTest.php @@ -27,7 +27,7 @@ public function expandBorderShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->expandBorderShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -60,7 +60,7 @@ public function expandFontShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->expandFontShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -116,7 +116,7 @@ public function expandBackgroundShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->expandBackgroundShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -169,7 +169,7 @@ public function expandDimensionsShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->expandDimensionsShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -207,7 +207,7 @@ public function createBorderShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->createBorderShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -238,7 +238,7 @@ public function createFontShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->createFontShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -281,7 +281,7 @@ public function createDimensionsShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->createDimensionsShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -319,7 +319,7 @@ public function createBackgroundShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->createBackgroundShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** From 7238d872da158d3709a386702503369a2ef82d04 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:47:21 +0100 Subject: [PATCH 32/63] Update phpstan/phpstan requirement from ^1.10.57 to ^1.10.58 (#473) Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.57...1.10.58) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a8e4d70d..6867153a 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "codacy/coverage": "^1.4.3", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.57", + "phpstan/phpstan": "^1.10.58", "phpstan/phpstan-phpunit": "^1.3.15", "phpunit/phpunit": "^8.5.36" }, From 3dd89b5a364b6a05232cd9ce3ce60d5243f669f9 Mon Sep 17 00:00:00 2001 From: JakeQZ Date: Tue, 13 Feb 2024 17:57:18 +0000 Subject: [PATCH 33/63] [BUGFIX] Allow at-rules to be parsed in strict mode (#456) The reverts the change to `CSSList` in https://github.com/MyIntervals/PHP-CSS-Parser/commit/134f4e62fe8ab9f316425f3c0f480b3f4f52d804 and adds a comment that `null` is an expected return value when the end of the list (or block) is reached. Fixes #352 --- CHANGELOG.md | 2 + src/CSSList/CSSList.php | 17 +++----- tests/CSSList/AtRuleBlockListTest.php | 62 +++++++++++++++++++++------ 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeddf48e..74ca75e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed +- Fix (regression) failure to parse at-rules with strict parsing (#456) + ## 8.5.0 ### Added diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index dcd8c331..603f662b 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -131,18 +131,15 @@ private static function parseListItem(ParserState $oParserState, CSSList $oList) } return $oAtRule; } elseif ($oParserState->comes('}')) { - if (!$oParserState->getSettings()->bLenientParsing) { - throw new UnexpectedTokenException('CSS selector', '}', 'identifier', $oParserState->currentLine()); - } else { - if ($bIsRoot) { - if ($oParserState->getSettings()->bLenientParsing) { - return DeclarationBlock::parse($oParserState); - } else { - throw new SourceException("Unopened {", $oParserState->currentLine()); - } + if ($bIsRoot) { + if ($oParserState->getSettings()->bLenientParsing) { + return DeclarationBlock::parse($oParserState); } else { - return null; + throw new SourceException("Unopened {", $oParserState->currentLine()); } + } else { + // End of list + return null; } } else { return DeclarationBlock::parse($oParserState, $oList); diff --git a/tests/CSSList/AtRuleBlockListTest.php b/tests/CSSList/AtRuleBlockListTest.php index cc234ce6..dcc8db5c 100644 --- a/tests/CSSList/AtRuleBlockListTest.php +++ b/tests/CSSList/AtRuleBlockListTest.php @@ -7,12 +7,46 @@ use Sabberworm\CSS\CSSList\AtRuleBlockList; use Sabberworm\CSS\Parser; use Sabberworm\CSS\Renderable; +use Sabberworm\CSS\Settings; /** * @covers \Sabberworm\CSS\CSSList\AtRuleBlockList */ final class AtRuleBlockListTest extends TestCase { + /** + * @return array + */ + public static function provideMinWidthMediaRule(): array + { + return [ + 'without spaces around arguments' => ['@media(min-width: 768px){.class{color:red}}'], + 'with spaces around arguments' => ['@media (min-width: 768px) {.class{color:red}}'], + ]; + } + + /** + * @return array + */ + public static function provideSyntacticlyCorrectAtRule(): array + { + return [ + 'media print' => ['@media print { html { background: white; color: black; } }'], + 'keyframes' => ['@keyframes mymove { from { top: 0px; } }'], + 'supports' => [' + @supports (display: flex) { + .flex-container > * { + text-shadow: 0 0 2px blue; + float: none; + } + .flex-container { + display: flex; + } + } + '], + ]; + } + /** * @test */ @@ -43,23 +77,12 @@ public function implementsCommentable() self::assertInstanceOf(Commentable::class, $subject); } - /** - * @return array> - */ - public static function mediaRuleDataProvider() - { - return [ - 'without spaces around arguments' => ['@media(min-width: 768px){.class{color:red}}'], - 'with spaces around arguments' => ['@media (min-width: 768px) {.class{color:red}}'], - ]; - } - /** * @test * * @param string $css * - * @dataProvider mediaRuleDataProvider + * @dataProvider provideMinWidthMediaRule */ public function parsesRuleNameOfMediaQueries($css) { @@ -74,7 +97,7 @@ public function parsesRuleNameOfMediaQueries($css) * * @param string $css * - * @dataProvider mediaRuleDataProvider + * @dataProvider provideMinWidthMediaRule */ public function parsesArgumentsOfMediaQueries($css) { @@ -83,4 +106,17 @@ public function parsesArgumentsOfMediaQueries($css) self::assertSame('(min-width: 768px)', $atRuleBlockList->atRuleArgs()); } + + /** + * @test + * + * @dataProvider provideMinWidthMediaRule + * @dataProvider provideSyntacticlyCorrectAtRule + */ + public function parsesSyntacticlyCorrectAtRuleInStrictMode(string $css): void + { + $contents = (new Parser($css, Settings::create()->beStrict()))->parse()->getContents(); + + self::assertNotEmpty($contents, 'Failing CSS: `' . $css . '`'); + } } From 870c45381e28d0e65ca1c35c97fac9b242ca72eb Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 15 Feb 2024 02:34:02 +0100 Subject: [PATCH 34/63] [TASK] Mark the public class constants as `@internal` (#472) Fixes #471 --- src/Parsing/ParserState.php | 2 ++ src/Property/AtRule.php | 4 ++++ src/Property/KeyframeSelector.php | 2 ++ src/Property/Selector.php | 2 ++ 4 files changed, 10 insertions(+) diff --git a/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index b60e0e06..06b083e6 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -9,6 +9,8 @@ class ParserState { /** * @var null + * + * @internal */ public const EOF = null; diff --git a/src/Property/AtRule.php b/src/Property/AtRule.php index df09b5fa..64efd4de 100644 --- a/src/Property/AtRule.php +++ b/src/Property/AtRule.php @@ -12,6 +12,8 @@ interface AtRule extends Renderable, Commentable * we’re whitelisting the block rules and have anything else be treated as a set rule. * * @var string + * + * @internal */ public const BLOCK_RULES = 'media/document/supports/region-style/font-feature-values'; @@ -19,6 +21,8 @@ interface AtRule extends Renderable, Commentable * … and more font-specific ones (to be used inside font-feature-values) * * @var string + * + * @internal */ public const SET_RULES = 'font-face/counter-style/page/swash/styleset/annotation'; diff --git a/src/Property/KeyframeSelector.php b/src/Property/KeyframeSelector.php index e44df1f9..7675252c 100644 --- a/src/Property/KeyframeSelector.php +++ b/src/Property/KeyframeSelector.php @@ -8,6 +8,8 @@ class KeyframeSelector extends Selector * regexp for specificity calculations * * @var string + * + * @internal */ public const SELECTOR_VALIDATION_RX = '/ ^( diff --git a/src/Property/Selector.php b/src/Property/Selector.php index 4fc734e9..0bf433d1 100644 --- a/src/Property/Selector.php +++ b/src/Property/Selector.php @@ -49,6 +49,8 @@ class Selector * regexp for specificity calculations * * @var string + * + * @internal */ public const SELECTOR_VALIDATION_RX = '/ ^( From dd81ad89ac38d85a6891af7eabcad5e46730e645 Mon Sep 17 00:00:00 2001 From: JakeQZ Date: Sat, 17 Feb 2024 09:55:47 +0000 Subject: [PATCH 35/63] [FEATURE] Add --diff to PHP-CS-Fixer CI dry-run command (#480) This helps quickly identify the problem. E.g. Before: ```cmd d:\dev\php-css-parser>composer ci:php:fixer > @php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots bin src tests PHP CS Fixer 3.49.0 (b6dc318) Insomnia by Fabien Potencier, Dariusz Ruminski and contributors. PHP runtime: 7.4.16 Loaded config default from "config/php-cs-fixer.php". ............................................... 1) tests\Value\SizeTest.php (function_declaration, php_unit_fqcn_annotation) Found 1 of 52 files that can be fixed in 1.802 seconds, 20.000 MB memory used ..F.. 52 / 52 (100%) Legend: .-no changes, F-fixed, S-skipped (cached or empty file), I-invalid file syntax (file ignored), E-error Script @php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots bin src tests handling the ci:php:fixer event returned with error code 8 ``` Not possible to know what the problem is without further investigation. After: ```cmd d:\dev\php-css-parser>composer ci:php:fixer > @php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff bin src tests 1) tests\Value\SizeTest.php (php_unit_fqcn_annotation) ---------- begin diff ---------- --- D:\dev\php-css-parser\tests\Value\SizeTest.php +++ D:\dev\php-css-parser\tests\Value\SizeTest.php @@ -8,7 +8,7 @@ use Sabberworm\CSS\Value\Size; /** - * @covers Size + * @covers \Size */ final class SizeTest extends TestCase { ----------- end diff ----------- Found 1 of 52 files that can be fixed in 0.029 seconds, 14.000 MB memory used PHP CS Fixer 3.49.0 (b6dc318) Insomnia by Fabien Potencier, Dariusz Ruminski and contributors. PHP runtime: 7.4.16 Loaded config default from "config/php-cs-fixer.php". Using cache file ".php-cs-fixer.cache". SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSS 52 / 52 (100%) Legend: .-no changes, F-fixed, S-skipped (cached or empty file), I-invalid file syntax (file ignored), E-error Script @php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff bin src tests handling the ci:php:fixer event returned with error code 8 ``` It's now clear what the problem is, and it can be simply resolved. In this case the suggested fix was not correct. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6867153a..ab7dc040 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,7 @@ "ci": [ "@ci:static" ], - "ci:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots bin src tests", + "ci:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff bin src tests", "ci:php:stan": "phpstan --no-progress --configuration=config/phpstan.neon", "ci:static": [ "@ci:php:fixer", From cb78396397a8b53845ddba721ca7d1d3a59ae0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20K=C3=B6nig?= <50620424+KaiOnGitHub@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:07:39 +0100 Subject: [PATCH 36/63] [FEATURE] Add support for the `dvh`, `lvh` and `svh` length units (#415) Fixes #412 For now, the `TestCase` just tests that all the unit values are parsed. (Other tests can be added here, but are beyond the scope of this change.) Co-authored-by: Raphael Schweikert Co-authored-by: Jake Hotson Co-authored-by: Oliver Klee --- CHANGELOG.md | 1 + src/Value/Size.php | 7 +++++- tests/Value/SizeTest.php | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/Value/SizeTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ca75e2..60e1e140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Added +- Add support for the `dvh`, `lvh` and `svh` length units (#415) - Add more tests (#449) ### Changed diff --git a/src/Value/Size.php b/src/Value/Size.php index 46036f94..f8336b1f 100644 --- a/src/Value/Size.php +++ b/src/Value/Size.php @@ -17,7 +17,12 @@ class Size extends PrimitiveValue * * @var array */ - private const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem']; + private const ABSOLUTE_SIZE_UNITS = [ + 'px', 'pt', 'pc', + 'cm', 'mm', 'mozmm', 'in', + 'vh', 'dvh', 'svh', 'lvh', + 'vw', 'vmin', 'vmax', 'rem', + ]; /** * @var array diff --git a/tests/Value/SizeTest.php b/tests/Value/SizeTest.php new file mode 100644 index 00000000..3aecce05 --- /dev/null +++ b/tests/Value/SizeTest.php @@ -0,0 +1,51 @@ + + */ + public static function provideUnit(): array + { + $units = [ + 'px', 'pt', 'pc', + 'cm', 'mm', 'mozmm', 'in', + 'vh', 'dvh', 'svh', 'lvh', + 'vw', 'vmin', 'vmax', 'rem', + '%', 'em', 'ex', 'ch', 'fr', + 'deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz', + ]; + + return \array_combine( + $units, + \array_map( + function (string $unit): array { + return [$unit]; + }, + $units + ) + ); + } + + /** + * @test + * + * @dataProvider provideUnit + */ + public function parsesUnit(string $unit): void + { + $subject = Size::parse(new ParserState('1' . $unit, Settings::create())); + + self::assertSame($unit, $subject->getUnit()); + } +} From a8d85df2ceb6bea9952517c14923e0aef5506b6f Mon Sep 17 00:00:00 2001 From: JakeQZ Date: Sat, 17 Feb 2024 18:42:14 +0000 Subject: [PATCH 37/63] [DOC] Fix typo in PHPStan script description (#483) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ab7dc040..3ce352a9 100644 --- a/composer.json +++ b/composer.json @@ -83,6 +83,6 @@ "ci:static": "Runs all static code analysis checks for the code.", "fix:php": "Autofixes all autofixable issues in the PHP code.", "fix:php:fixer": "Fixes autofixable issues found by PHP CS Fixer.", - "phpstand:baseline": "Updates the PHPStan baseline file to match the code." + "phpstan:baseline": "Updates the PHPStan baseline file to match the code." } } From 848685ad7f2a6fbc1ea19987468e1969f2f1d02b Mon Sep 17 00:00:00 2001 From: JakeQZ Date: Sat, 17 Feb 2024 19:04:42 +0000 Subject: [PATCH 38/63] [BUGFIX] Invoke PHIVE-installed tools via shell (#484) On Windows, the `.phive` directory contains batch files that in turn invoke the phar installed elsewhere on the system. To be compatible with both Linux and Windows, the file must be invoked directly via the shell, and without a file extension specified (when invoked as well as when installed). Fixes #479. --- .phive/phars.xml | 2 +- composer.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.phive/phars.xml b/.phive/phars.xml index 3d509be9..1a0b991a 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,4 +1,4 @@ - + diff --git a/composer.json b/composer.json index 3ce352a9..8fd8a109 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,7 @@ "ci": [ "@ci:static" ], - "ci:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff bin src tests", + "ci:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff bin src tests", "ci:php:stan": "phpstan --no-progress --configuration=config/phpstan.neon", "ci:static": [ "@ci:php:fixer", @@ -73,7 +73,7 @@ "fix:php": [ "@fix:php:fixer" ], - "fix:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix bin src tests", + "fix:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix bin src tests", "phpstan:baseline": "phpstan --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon" }, "scripts-descriptions": { From 6a5d91d4b068e6867b6b7119937b675cd2fddc1a Mon Sep 17 00:00:00 2001 From: Ali Khalili Date: Tue, 20 Feb 2024 22:02:10 +0100 Subject: [PATCH 39/63] [BUGFIX] Handle incorrect RGB colors better (#485) Handle incorrect inputs color which have less than 6 chars --- CHANGELOG.md | 1 + src/Value/Color.php | 9 ++++++++- tests/ParserTest.php | 2 ++ tests/fixtures/colortest.css | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60e1e140..97c3bfe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed +- Fix PHP notice caused by parsing invalid color values having less than 6 charachters (#485) - Fix (regression) failure to parse at-rules with strict parsing (#456) ## 8.5.0 diff --git a/src/Value/Color.php b/src/Value/Color.php index 1cf00cce..5daad412 100644 --- a/src/Value/Color.php +++ b/src/Value/Color.php @@ -56,12 +56,19 @@ public static function parse(ParserState $oParserState, $bIgnoreCase = false) $oParserState->currentLine() ), ]; - } else { + } elseif ($oParserState->strlen($sValue) === 6) { $aColor = [ 'r' => new Size(intval($sValue[0] . $sValue[1], 16), null, true, $oParserState->currentLine()), 'g' => new Size(intval($sValue[2] . $sValue[3], 16), null, true, $oParserState->currentLine()), 'b' => new Size(intval($sValue[4] . $sValue[5], 16), null, true, $oParserState->currentLine()), ]; + } else { + throw new UnexpectedTokenException( + 'Invalid hex color value', + $sValue, + 'custom', + $oParserState->currentLine() + ); } } else { $sColorMode = $oParserState->parseIdentifier(true); diff --git a/tests/ParserTest.php b/tests/ParserTest.php index c5ddeb44..a48ac0e7 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -146,6 +146,8 @@ public function colorParsing() 'l' => new Size(220.0, '%', true, $oColor->getLineNo()), 'a' => new Size(0000.3, null, true, $oColor->getLineNo()), ], $oColor->getColor()); + $aColorRule = $oRuleSet->getRules('outline-color'); + self::assertEmpty($aColorRule); } } foreach ($oDoc->getAllValues('color') as $sColor) { diff --git a/tests/fixtures/colortest.css b/tests/fixtures/colortest.css index 1c89cf41..f834aa77 100644 --- a/tests/fixtures/colortest.css +++ b/tests/fixtures/colortest.css @@ -9,6 +9,7 @@ #yours { background-color: hsl(220, 10%, 220%); background-color: hsla(220, 10%, 220%, 0.3); + outline-color: #22; } #variables { From 97cee41d562bfbdcc69fef45d07995664cf45fe5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:47:12 +0100 Subject: [PATCH 40/63] Update phpstan/phpstan requirement from ^1.10.58 to ^1.10.59 (#487) Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.58...1.10.59) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8fd8a109..0e27aadf 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "codacy/coverage": "^1.4.3", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.58", + "phpstan/phpstan": "^1.10.59", "phpstan/phpstan-phpunit": "^1.3.15", "phpunit/phpunit": "^8.5.36" }, From 822bb72452e94f6f4dc5326f1b0ce9e603189e7b Mon Sep 17 00:00:00 2001 From: JakeQZ Date: Thu, 22 Feb 2024 08:20:53 +0000 Subject: [PATCH 41/63] [FEATURE] Add Composer scripts to run unit tests (#488) The `ci` script now also runs `ci:dynamic` which in turn runs `ci:tests`. The PHPUnit cache is only applicable if the configuration is to run previously failing tests first, which it isn't, hence `--do-not-cache-result`. Also update the readme instructions for running all code checks. Relates to #486. --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00567417..35b9fac4 100644 --- a/README.md +++ b/README.md @@ -633,5 +633,17 @@ class Sabberworm\CSS\CSSList\Document#4 (2) { ## Misc -* Legacy Support: The latest pre-PSR-0 version of this project can be checked with the `0.9.0` tag. -* Running Tests: To run all unit tests for this project, run `composer install` to install phpunit and use `./vendor/bin/phpunit`. +### Legacy Support + +The latest pre-PSR-0 version of this project can be checked with the `0.9.0` tag. + +### Running Tests + +To run all continuous integration (CI) checks for this project (including unit tests), +* run `composer install` to install the development dependencies managed with Composer; +* run `phive install` to install the development dependencies managed with PHIVE; + * [Installation of PHIVE](https://github.com/phar-io/phive?tab=readme-ov-file#getting-phive) +* run `composer ci` to run all static and dynamic CI checks. + +Details of other Composer scripts available (e.g. to run one specific CI check) are provided with `composer list`. + From 3fa132608d87b6497fe587cde11d3cc7efd0cf87 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 22 Feb 2024 11:43:17 +0100 Subject: [PATCH 42/63] [DOCS] Fix typo in the changelog (#491) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97c3bfe6..063cad71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed -- Fix PHP notice caused by parsing invalid color values having less than 6 charachters (#485) +- Fix PHP notice caused by parsing invalid color values having less than 6 characters (#485) - Fix (regression) failure to parse at-rules with strict parsing (#456) ## 8.5.0 From 5474968c1abbf1fdcc7db193b126eab82d7ba230 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:02:29 +0100 Subject: [PATCH 43/63] Update phpstan/phpstan-phpunit requirement from ^1.3.15 to ^1.3.16 (#492) Updates the requirements on [phpstan/phpstan-phpunit](https://github.com/phpstan/phpstan-phpunit) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan-phpunit/releases) - [Commits](https://github.com/phpstan/phpstan-phpunit/compare/1.3.15...1.3.16) --- updated-dependencies: - dependency-name: phpstan/phpstan-phpunit dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0e27aadf..790142af 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "codacy/coverage": "^1.4.3", "phpstan/extension-installer": "^1.3.1", "phpstan/phpstan": "^1.10.59", - "phpstan/phpstan-phpunit": "^1.3.15", + "phpstan/phpstan-phpunit": "^1.3.16", "phpunit/phpunit": "^8.5.36" }, "suggest": { From 9ea46506066237ee4bfde119d8244148c8879137 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sat, 24 Feb 2024 18:30:42 +0100 Subject: [PATCH 44/63] [TASK] Update PHP-CS-Fixer (#493) https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/tag/v3.50.0 --- .phive/phars.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.phive/phars.xml b/.phive/phars.xml index 1a0b991a..8b65eea8 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,4 +1,4 @@ - + From 8f94950c4c2f6831c0abbfd31d637707ad4b90c6 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 26 Feb 2024 14:44:32 +0100 Subject: [PATCH 45/63] [DOCS] Add a class diagram (#482) This diagram aims to provide an overview of which classes we have and how their are interconnected. Hence, it does not contain any methods or properties. As the Mermaid render on GitHub does not support namespace, the classes are not grouped into namespaces in the diagram. Fixes #422 --- CHANGELOG.md | 1 + README.md | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 063cad71..aa931b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Added +- Add a class diagram to the README (#482) - Add support for the `dvh`, `lvh` and `svh` length units (#415) - Add more tests (#449) diff --git a/README.md b/README.md index 35b9fac4..776711f1 100644 --- a/README.md +++ b/README.md @@ -615,6 +615,217 @@ class Sabberworm\CSS\CSSList\Document#4 (2) { #header {margin: 10px 2em 1cm 2%;font-family: Verdana,Helvetica,"Gill Sans",sans-serif;color: red !important;} ``` +## Class diagram + +```mermaid +classDiagram + direction LR + + %% top namespace + + class OutputFormat { + } + + class OutputFormatter { + } + + OutputFormatter --> "1" OutputFormat : oFormat + OutputFormat --> "1" OutputFormatter : oFormatter + OutputFormat --> "1" OutputFormat : oNextLevelFormat + + class Parser { + } + + class ParserState { + } + + Parser --> "1" ParserState : oParserState + + class Renderable { + <> + } + + class Settings { + } + + + %% namespace Comment + + class Comment { + } + class Commentable { + <> + } + + Comment ..|> Renderable + + + %% namespace CSSList + + class AtRuleBlockList { + } + class CSSBlockList { + <> + } + class CSSList { + <> + } + class Document { + } + class KeyFrame { + } + + AtRuleBlockList --|> CSSBlockList + AtRuleBlockList ..|> AtRule + CSSBlockList --|> CSSList + CSSList ..|> Renderable + CSSList ..|> Commentable + Document --|> CSSBlockList + KeyFrame --|> CSSList + KeyFrame ..|> AtRule + + CSSList --> "*" Comment : aComments + CSSList --> "*" RuleSet : aContents + CSSList --> "*" CSSList : aContents + CSSList --> "*" Import : aContents + CSSList --> "*" Charset : aContents + + %% namespace Parsing + + class Anchor { + } + class OutputException { + } + class ParserState { + } + class SourceException { + } + class UnexpectedEOFException { + } + class UnexpectedTokenException { + } + + OutputException --|> SourceException + UnexpectedEOFException --|> UnexpectedTokenException + UnexpectedTokenException --|> SourceException + + Anchor --> "1" ParserState : oParserState + ParserState --> "1" Settings : oParserSettings + + %% namespace Property + + class AtRule { + <> + } + class Charset { + } + class CSSNamespace { + } + class Import { + } + class KeyframeSelector { + } + class Selector { + } + + AtRule --|> Renderable + AtRule --|> Commentable + Charset ..|> AtRule + CSSNamespace ..|> AtRule + Import ..|> AtRule + KeyframeSelector --|> Selector + + Charset --> "1" CSSString : oCharset + Charset --> "*" Comment : aComments + CSSNamespace --> "*" Comment : aComments + Import --> "*" Comment : aComments + + + %% namespace Rule + + class Rule { + } + + Rule ..|> Renderable + Rule ..|> Commentable + + Rule --> "1" RuleValueList : mValue + Rule --> "*" Comment : aComments + + + %% namespace RuleSet + + class AtRuleSet { + } + class DeclarationBlock { + } + class RuleSet { + <> + } + + AtRuleSet --|> RuleSet + AtRuleSet ..|> AtRule + DeclarationBlock --|> RuleSet + RuleSet ..|> Renderable + RuleSet ..|> Commentable + + DeclarationBlock --> "*" Selector : aSelectors + RuleSet --> "*" Rule : aRules + RuleSet --> "*" Comment : aComments + + + %% namespace Value + + class CalcFunction { + } + class CalcRuleValueList { + } + class Color { + } + class CSSFunction { + } + class CSSString { + } + class LineName { + } + class PrimitiveValue { + <> + } + class RuleValueList { + } + class Size { + } + class URL { + } + class Value { + <> + } + class ValueList { + <> + } + + CalcFunction --|> CSSFunction + CalcRuleValueList --|> RuleValueList + Color --|> CSSFunction + CSSFunction --|> ValueList + CSSString --|> PrimitiveValue + LineName --|> ValueList + PrimitiveValue --|> Value + RuleValueList --|> ValueList + Size --|> PrimitiveValue + URL --|> PrimitiveValue + Value ..|> Renderable + ValueList --|> Value + + URL --> "1" CSSString : oURL + ValueList --> "*" RuleValueList : aComponents + ValueList --> "*" CSSFunction : aComponents + ValueList --> "*" CSSString : aComponents + ValueList --> "*" LineName : aComponents + ValueList --> "*" Size : aComponents + ValueList --> "*" URL : aComponents +``` + ## Contributors/Thanks to * [oliverklee](https://github.com/oliverklee) for lots of refactorings, code modernizations and CI integrations From b2ba983e8b6f9e718f97b48130e1ed96126784fa Mon Sep 17 00:00:00 2001 From: Bart Butler Date: Mon, 26 Feb 2024 20:21:27 +0100 Subject: [PATCH 46/63] [TASK] Avoid poor scaling of `array_search()` with very long arrays (#413) When there were many many elements in `$aStack`, starting the delimiter search from the beginning for each loop iteration was very slow. This is addressed by building a new array, rather than modifying `$aStack` in place, and iterating over it in a single pass. A particular 1.6M style string is now parsed in 5 seconds rather than 4 minutes. --- CHANGELOG.md | 1 + src/Value/Value.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa931b90..f31a4a61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Changed +- Improve performance of Value::parseValue with many delimiters by refactoring to remove array_search() - Add visibility to all class/interface constants (#469) ### Deprecated diff --git a/src/Value/Value.php b/src/Value/Value.php index ce6d5790..6be2110c 100644 --- a/src/Value/Value.php +++ b/src/Value/Value.php @@ -67,23 +67,30 @@ public static function parseValue(ParserState $oParserState, array $aListDelimit } // Convert the list to list objects foreach ($aListDelimiters as $sDelimiter) { - if (count($aStack) === 1) { + $iStackLength = count($aStack); + if ($iStackLength === 1) { return $aStack[0]; } - $iStartPosition = null; - while (($iStartPosition = array_search($sDelimiter, $aStack, true)) !== false) { + $aNewStack = []; + for ($iStartPosition = 0; $iStartPosition < $iStackLength; ++$iStartPosition) { + if ($iStartPosition === ($iStackLength - 1) || $sDelimiter !== $aStack[$iStartPosition + 1]) { + $aNewStack[] = $aStack[$iStartPosition]; + continue; + } $iLength = 2; //Number of elements to be joined - for ($i = $iStartPosition + 2; $i < count($aStack); $i += 2, ++$iLength) { + for ($i = $iStartPosition + 3; $i < $iStackLength; $i += 2, ++$iLength) { if ($sDelimiter !== $aStack[$i]) { break; } } $oList = new RuleValueList($sDelimiter, $oParserState->currentLine()); - for ($i = $iStartPosition - 1; $i - $iStartPosition + 1 < $iLength * 2; $i += 2) { + for ($i = $iStartPosition; $i - $iStartPosition < $iLength * 2; $i += 2) { $oList->addListComponent($aStack[$i]); } - array_splice($aStack, $iStartPosition - 1, $iLength * 2 - 1, [$oList]); + $aNewStack[] = $oList; + $iStartPosition += $iLength * 2 - 2; } + $aStack = $aNewStack; } if (!isset($aStack[0])) { throw new UnexpectedTokenException( From 3a461e0424449ddcf86ed09b7bbee8b4349433ea Mon Sep 17 00:00:00 2001 From: JakeQZ Date: Tue, 27 Feb 2024 08:32:44 +0000 Subject: [PATCH 47/63] [FEATURE] Add Composer scripts to run unit tests (#503) The `ci` script now also runs `ci:dynamic` which in turn runs `ci:tests`. The PHPUnit cache is only applicable if the configuration is to run previously failing tests first, which it isn't, hence `--do-not-cache-result`. Also update the readme instructions for running all code checks. Relates to #486. --- composer.json | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 790142af..9a818840 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,11 @@ }, "scripts": { "ci": [ - "@ci:static" + "@ci:static", + "@ci:dynamic" + ], + "ci:dynamic": [ + "@ci:tests" ], "ci:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff bin src tests", "ci:php:stan": "phpstan --no-progress --configuration=config/phpstan.neon", @@ -70,6 +74,11 @@ "@ci:php:fixer", "@ci:php:stan" ], + "ci:tests": [ + "@ci:tests:unit" + ], + "ci:tests:sof": "\"./vendor/bin/phpunit\" --stop-on-failure --do-not-cache-result", + "ci:tests:unit": "\"./vendor/bin/phpunit\" --do-not-cache-result", "fix:php": [ "@fix:php:fixer" ], @@ -77,10 +86,14 @@ "phpstan:baseline": "phpstan --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon" }, "scripts-descriptions": { - "ci": "Runs all dynamic and static code checks (i.e. currently, only the static checks).", + "ci": "Runs all dynamic and static code checks.", + "ci:dynamic": "Runs all dynamic code checks (i.e., currently, the unit tests).", "ci:php:fixer": "Checks the code style with PHP CS Fixer.", "ci:php:stan": "Checks the types with PHPStan.", "ci:static": "Runs all static code analysis checks for the code.", + "ci:tests": "Runs all dynamic tests (i.e., currently, the unit tests).", + "ci:tests:sof": "Runs the unit tests and stops at the first failure.", + "ci:tests:unit": "Runs all unit tests.", "fix:php": "Autofixes all autofixable issues in the PHP code.", "fix:php:fixer": "Fixes autofixable issues found by PHP CS Fixer.", "phpstan:baseline": "Updates the PHPStan baseline file to match the code." From f9f3e403e3c79f4e14e3cd15677622eb9e0e1491 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Wed, 28 Feb 2024 00:37:36 +0100 Subject: [PATCH 48/63] [TASK] Reorder things in the class diagram source code (#505) Move the associations to the bottom of the code. Also sort them. This helps us use an autogenerated diagram to which we add the associations (as the our tool of choice does not generate the associations for the diagram). --- README.md | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 776711f1..309b99d0 100644 --- a/README.md +++ b/README.md @@ -629,18 +629,12 @@ classDiagram class OutputFormatter { } - OutputFormatter --> "1" OutputFormat : oFormat - OutputFormat --> "1" OutputFormatter : oFormatter - OutputFormat --> "1" OutputFormat : oNextLevelFormat - class Parser { } class ParserState { } - Parser --> "1" ParserState : oParserState - class Renderable { <> } @@ -684,11 +678,6 @@ classDiagram KeyFrame --|> CSSList KeyFrame ..|> AtRule - CSSList --> "*" Comment : aComments - CSSList --> "*" RuleSet : aContents - CSSList --> "*" CSSList : aContents - CSSList --> "*" Import : aContents - CSSList --> "*" Charset : aContents %% namespace Parsing @@ -709,8 +698,6 @@ classDiagram UnexpectedEOFException --|> UnexpectedTokenException UnexpectedTokenException --|> SourceException - Anchor --> "1" ParserState : oParserState - ParserState --> "1" Settings : oParserSettings %% namespace Property @@ -735,11 +722,6 @@ classDiagram Import ..|> AtRule KeyframeSelector --|> Selector - Charset --> "1" CSSString : oCharset - Charset --> "*" Comment : aComments - CSSNamespace --> "*" Comment : aComments - Import --> "*" Comment : aComments - %% namespace Rule @@ -749,9 +731,6 @@ classDiagram Rule ..|> Renderable Rule ..|> Commentable - Rule --> "1" RuleValueList : mValue - Rule --> "*" Comment : aComments - %% namespace RuleSet @@ -769,10 +748,6 @@ classDiagram RuleSet ..|> Renderable RuleSet ..|> Commentable - DeclarationBlock --> "*" Selector : aSelectors - RuleSet --> "*" Rule : aRules - RuleSet --> "*" Comment : aComments - %% namespace Value @@ -817,11 +792,31 @@ classDiagram Value ..|> Renderable ValueList --|> Value + Anchor --> "1" ParserState : oParserState + CSSList --> "*" CSSList : aContents + CSSList --> "*" Charset : aContents + CSSList --> "*" Comment : aComments + CSSList --> "*" Import : aContents + CSSList --> "*" RuleSet : aContents + CSSNamespace --> "*" Comment : aComments + Charset --> "*" Comment : aComments + Charset --> "1" CSSString : oCharset + DeclarationBlock --> "*" Selector : aSelectors + Import --> "*" Comment : aComments + OutputFormat --> "1" OutputFormat : oNextLevelFormat + OutputFormat --> "1" OutputFormatter : oFormatter + OutputFormatter --> "1" OutputFormat : oFormat + Parser --> "1" ParserState : oParserState + ParserState --> "1" Settings : oParserSettings + Rule --> "*" Comment : aComments + Rule --> "1" RuleValueList : mValue + RuleSet --> "*" Comment : aComments + RuleSet --> "*" Rule : aRules URL --> "1" CSSString : oURL - ValueList --> "*" RuleValueList : aComponents ValueList --> "*" CSSFunction : aComponents ValueList --> "*" CSSString : aComponents ValueList --> "*" LineName : aComponents + ValueList --> "*" RuleValueList : aComponents ValueList --> "*" Size : aComponents ValueList --> "*" URL : aComponents ``` From 4108ca8f7a0c775b2bf95a3683a7e06a37ed487b Mon Sep 17 00:00:00 2001 From: Mathieu Rochette Date: Wed, 28 Feb 2024 23:48:12 +0100 Subject: [PATCH 49/63] [TASK] Add more tests for parsing of invalid colors --- tests/RuleSet/LenientParsingTest.php | 22 ++++++++++++++++++++++ tests/fixtures/invalid-color.css | 11 +++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/fixtures/invalid-color.css diff --git a/tests/RuleSet/LenientParsingTest.php b/tests/RuleSet/LenientParsingTest.php index 54d63e5b..39e7bf74 100644 --- a/tests/RuleSet/LenientParsingTest.php +++ b/tests/RuleSet/LenientParsingTest.php @@ -131,4 +131,26 @@ public function caseInsensitivity() $oResult->render() ); } + + /** + * @test + */ + public function invalidColor() + { + $sFile = __DIR__ . '/../fixtures/invalid-color.css'; + $oParser = new Parser(file_get_contents($sFile), Settings::create()->withLenientParsing(true)); + $oParser->parse(); + } + + /** + * @test + */ + public function invalidColorStrict() + { + $this->expectException(UnexpectedTokenException::class); + + $sFile = __DIR__ . '/../fixtures/invalid-color.css'; + $oParser = new Parser(file_get_contents($sFile), Settings::create()->beStrict()); + $oParser->parse(); + } } diff --git a/tests/fixtures/invalid-color.css b/tests/fixtures/invalid-color.css new file mode 100644 index 00000000..31602f37 --- /dev/null +++ b/tests/fixtures/invalid-color.css @@ -0,0 +1,11 @@ +#test { + color: #a; + background: #ab; +} + +body + color: #abcd; + background: #abcde; +} + +a { color: #fffff;} From 0d69060a0330984095e7352f5d2319a5ac4f578a Mon Sep 17 00:00:00 2001 From: JakeQZ Date: Thu, 29 Feb 2024 09:14:56 +0000 Subject: [PATCH 50/63] [DOCS] Correct typo in class diagram ("abstruct" -> "abstract") (#509) --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 309b99d0..e8ed9268 100644 --- a/README.md +++ b/README.md @@ -659,10 +659,10 @@ classDiagram class AtRuleBlockList { } class CSSBlockList { - <> + <> } class CSSList { - <> + <> } class Document { } @@ -739,7 +739,7 @@ classDiagram class DeclarationBlock { } class RuleSet { - <> + <> } AtRuleSet --|> RuleSet @@ -764,7 +764,7 @@ classDiagram class LineName { } class PrimitiveValue { - <> + <> } class RuleValueList { } @@ -773,10 +773,10 @@ classDiagram class URL { } class Value { - <> + <> } class ValueList { - <> + <> } CalcFunction --|> CSSFunction From 498d504f0dc0e39c86b7f954d82a289012893ec4 Mon Sep 17 00:00:00 2001 From: JakeQZ Date: Thu, 29 Feb 2024 09:15:30 +0000 Subject: [PATCH 51/63] [DOCS] Remove trailing whitespace in README.md (#508) This avoids spurious differences appearing after using an editor that automatically removes trailing whitespace. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e8ed9268..337c9158 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ foreach($cssDocument->getAllRuleSets() as $oRuleSet) { // Note that the added dash will make this remove all rules starting with // `font-` (like `font-size`, `font-weight`, etc.) as well as a potential // `font` rule. - $oRuleSet->removeRule('font-'); + $oRuleSet->removeRule('font-'); $oRuleSet->removeRule('cursor'); } ``` @@ -625,20 +625,20 @@ classDiagram class OutputFormat { } - + class OutputFormatter { } - + class Parser { } - + class ParserState { } class Renderable { <> } - + class Settings { } From 086fa00e5f03b87ca6636dcc65b6601fc9c46d77 Mon Sep 17 00:00:00 2001 From: JakeQZ Date: Fri, 1 Mar 2024 09:06:51 +0000 Subject: [PATCH 52/63] [CLEANUP] Use common ancestor `Value` in type specifications (#507) Replace the list of various possible sub-types with the common ancestor. Update the class diagram to indicate that `ValueList::$aComponents` no longer has a dependency on the sub-types definitions. Resolves #499. Supersedes and closes #506. --- README.md | 7 +------ src/Value/CSSFunction.php | 4 ++-- src/Value/Color.php | 6 +++--- src/Value/LineName.php | 2 +- src/Value/Value.php | 4 ++-- src/Value/ValueList.php | 11 +++++------ 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 337c9158..904a26c8 100644 --- a/README.md +++ b/README.md @@ -813,12 +813,7 @@ classDiagram RuleSet --> "*" Comment : aComments RuleSet --> "*" Rule : aRules URL --> "1" CSSString : oURL - ValueList --> "*" CSSFunction : aComponents - ValueList --> "*" CSSString : aComponents - ValueList --> "*" LineName : aComponents - ValueList --> "*" RuleValueList : aComponents - ValueList --> "*" Size : aComponents - ValueList --> "*" URL : aComponents + ValueList --> "*" Value : aComponents ``` ## Contributors/Thanks to diff --git a/src/Value/CSSFunction.php b/src/Value/CSSFunction.php index 300dc3ec..e3235c81 100644 --- a/src/Value/CSSFunction.php +++ b/src/Value/CSSFunction.php @@ -18,7 +18,7 @@ class CSSFunction extends ValueList /** * @param string $sName - * @param RuleValueList|array $aArguments + * @param RuleValueList|array $aArguments * @param string $sSeparator * @param int $iLineNo */ @@ -72,7 +72,7 @@ public function setName($sName) } /** - * @return array + * @return array */ public function getArguments() { diff --git a/src/Value/Color.php b/src/Value/Color.php index 5daad412..55acdaaa 100644 --- a/src/Value/Color.php +++ b/src/Value/Color.php @@ -14,7 +14,7 @@ class Color extends CSSFunction { /** - * @param array $aColor + * @param array $aColor * @param int $iLineNo */ public function __construct(array $aColor, $iLineNo = 0) @@ -125,7 +125,7 @@ private static function mapRange($fVal, $fFromMin, $fFromMax, $fToMin, $fToMax) } /** - * @return array + * @return array */ public function getColor() { @@ -133,7 +133,7 @@ public function getColor() } /** - * @param array $aColor + * @param array $aColor * * @return void */ diff --git a/src/Value/LineName.php b/src/Value/LineName.php index e231ce38..6eaf7620 100644 --- a/src/Value/LineName.php +++ b/src/Value/LineName.php @@ -10,7 +10,7 @@ class LineName extends ValueList { /** - * @param array $aComponents + * @param array $aComponents * @param int $iLineNo */ public function __construct(array $aComponents = [], $iLineNo = 0) diff --git a/src/Value/Value.php b/src/Value/Value.php index 6be2110c..5b52a22d 100644 --- a/src/Value/Value.php +++ b/src/Value/Value.php @@ -30,14 +30,14 @@ public function __construct($iLineNo = 0) /** * @param array $aListDelimiters * - * @return RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string + * @return Value|string * * @throws UnexpectedTokenException * @throws UnexpectedEOFException */ public static function parseValue(ParserState $oParserState, array $aListDelimiters = []) { - /** @var array $aStack */ + /** @var array $aStack */ $aStack = []; $oParserState->consumeWhiteSpace(); //Build a list of delimiters and parsed values diff --git a/src/Value/ValueList.php b/src/Value/ValueList.php index a93acc7b..382c3baa 100644 --- a/src/Value/ValueList.php +++ b/src/Value/ValueList.php @@ -13,7 +13,7 @@ abstract class ValueList extends Value { /** - * @var array + * @var array */ protected $aComponents; @@ -23,8 +23,7 @@ abstract class ValueList extends Value protected $sSeparator; /** - * phpcs:ignore Generic.Files.LineLength - * @param array|RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $aComponents + * @param array|Value|string $aComponents * @param string $sSeparator * @param int $iLineNo */ @@ -39,7 +38,7 @@ public function __construct($aComponents = [], $sSeparator = ',', $iLineNo = 0) } /** - * @param RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $mComponent + * @param Value|string $mComponent * * @return void */ @@ -49,7 +48,7 @@ public function addListComponent($mComponent) } /** - * @return array + * @return array */ public function getListComponents() { @@ -57,7 +56,7 @@ public function getListComponents() } /** - * @param array $aComponents + * @param array $aComponents * * @return void */ From 2330f6d08a9b644f306d9a3e00dc9fd682e5880f Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 3 Mar 2024 01:28:32 +0100 Subject: [PATCH 53/63] [CLEANUP] Move some things in the class diagram code around (#513) This gets another thing out of the way towards moving to an autogenerated class diagram. Also sort the moved lines. --- README.md | 60 +++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 904a26c8..9a2ce637 100644 --- a/README.md +++ b/README.md @@ -651,8 +651,6 @@ classDiagram <> } - Comment ..|> Renderable - %% namespace CSSList @@ -669,15 +667,6 @@ classDiagram class KeyFrame { } - AtRuleBlockList --|> CSSBlockList - AtRuleBlockList ..|> AtRule - CSSBlockList --|> CSSList - CSSList ..|> Renderable - CSSList ..|> Commentable - Document --|> CSSBlockList - KeyFrame --|> CSSList - KeyFrame ..|> AtRule - %% namespace Parsing @@ -694,10 +683,6 @@ classDiagram class UnexpectedTokenException { } - OutputException --|> SourceException - UnexpectedEOFException --|> UnexpectedTokenException - UnexpectedTokenException --|> SourceException - %% namespace Property @@ -715,22 +700,12 @@ classDiagram class Selector { } - AtRule --|> Renderable - AtRule --|> Commentable - Charset ..|> AtRule - CSSNamespace ..|> AtRule - Import ..|> AtRule - KeyframeSelector --|> Selector - %% namespace Rule class Rule { } - Rule ..|> Renderable - Rule ..|> Commentable - %% namespace RuleSet @@ -742,12 +717,6 @@ classDiagram <> } - AtRuleSet --|> RuleSet - AtRuleSet ..|> AtRule - DeclarationBlock --|> RuleSet - RuleSet ..|> Renderable - RuleSet ..|> Commentable - %% namespace Value @@ -779,16 +748,41 @@ classDiagram <> } + AtRule --|> Commentable + AtRule --|> Renderable + AtRuleBlockList --|> CSSBlockList + AtRuleBlockList ..|> AtRule + AtRuleSet --|> RuleSet + AtRuleSet ..|> AtRule + CSSBlockList --|> CSSList + CSSFunction --|> ValueList + CSSList ..|> Commentable + CSSList ..|> Renderable + CSSNamespace ..|> AtRule + CSSString --|> PrimitiveValue CalcFunction --|> CSSFunction CalcRuleValueList --|> RuleValueList + Charset ..|> AtRule Color --|> CSSFunction - CSSFunction --|> ValueList - CSSString --|> PrimitiveValue + Comment ..|> Renderable + DeclarationBlock --|> RuleSet + Document --|> CSSBlockList + Import ..|> AtRule + KeyFrame --|> CSSList + KeyFrame ..|> AtRule + KeyframeSelector --|> Selector LineName --|> ValueList + OutputException --|> SourceException PrimitiveValue --|> Value + Rule ..|> Commentable + Rule ..|> Renderable + RuleSet ..|> Commentable + RuleSet ..|> Renderable RuleValueList --|> ValueList Size --|> PrimitiveValue URL --|> PrimitiveValue + UnexpectedEOFException --|> UnexpectedTokenException + UnexpectedTokenException --|> SourceException Value ..|> Renderable ValueList --|> Value From c4dbc102350283f75916c86d78bbbd45f382d7a3 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 3 Mar 2024 19:45:29 +0100 Subject: [PATCH 54/63] [TASK] Use a generated class/diagram list in the class diagram (#515) This is another step towards auto-generating more of the class diagram. --- README.md | 128 ++++++++++++++++++++---------------------------------- 1 file changed, 48 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 9a2ce637..e9cde784 100644 --- a/README.md +++ b/README.md @@ -621,133 +621,101 @@ class Sabberworm\CSS\CSSList\Document#4 (2) { classDiagram direction LR - %% top namespace + %% Start of the part generated from the PHP code using tasuku43/mermaid-class-diagram - class OutputFormat { + class Renderable { + <> } - - class OutputFormatter { + class DeclarationBlock { } - - class Parser { + class RuleSet { + <> } - - class ParserState { + class AtRuleSet { } - - class Renderable { + class KeyframeSelector { + } + class AtRule { <> } - - class Settings { + class Charset { } - - - %% namespace Comment - - class Comment { + class Import { } - class Commentable { - <> + class Selector { } - - - %% namespace CSSList - - class AtRuleBlockList { + class CSSNamespace { } - class CSSBlockList { - <> + class Settings { } - class CSSList { - <> + class Rule { } - class Document { + class Parser { } - class KeyFrame { + class OutputFormatter { } - - - %% namespace Parsing - - class Anchor { + class OutputFormat { } class OutputException { } - class ParserState { + class UnexpectedEOFException { } class SourceException { } - class UnexpectedEOFException { - } class UnexpectedTokenException { } - - - %% namespace Property - - class AtRule { - <> + class ParserState { } - class Charset { + class Anchor { } - class CSSNamespace { + class CSSBlockList { + <> } - class Import { + class Document { } - class KeyframeSelector { + class CSSList { + <> } - class Selector { + class KeyFrame { } - - - %% namespace Rule - - class Rule { + class AtRuleBlockList { } - - - %% namespace RuleSet - - class AtRuleSet { + class Color { } - class DeclarationBlock { + class URL { } - class RuleSet { - <> + class CalcRuleValueList { + } + class ValueList { + <> } - - - %% namespace Value - class CalcFunction { } - class CalcRuleValueList { + class LineName { } - class Color { + class Value { + <> } - class CSSFunction { + class Size { } class CSSString { } - class LineName { - } class PrimitiveValue { - <> + <> } - class RuleValueList { - } - class Size { + class CSSFunction { } - class URL { + class RuleValueList { } - class Value { - <> + class Commentable { + <> } - class ValueList { - <> + class Comment { } + %% end of the generated part + + AtRule --|> Commentable AtRule --|> Renderable AtRuleBlockList --|> CSSBlockList From 4b15eedaa6342ff5f3fab4cf710f66c178f417e3 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 5 Mar 2024 23:49:55 +0100 Subject: [PATCH 55/63] [TASK] Fix typo "abstruct" in the class diagram (again) (#517) This ends the abstruction of the class diagram. These typos in the class diagram were caused by a typo in the Mermaid generation tool, which is now fixed. https://github.com/tasuku43/php-mermaid-class-diagram/releases --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e9cde784..116f8911 100644 --- a/README.md +++ b/README.md @@ -629,7 +629,7 @@ classDiagram class DeclarationBlock { } class RuleSet { - <> + <> } class AtRuleSet { } @@ -669,12 +669,12 @@ classDiagram class Anchor { } class CSSBlockList { - <> + <> } class Document { } class CSSList { - <> + <> } class KeyFrame { } @@ -687,21 +687,21 @@ classDiagram class CalcRuleValueList { } class ValueList { - <> + <> } class CalcFunction { } class LineName { } class Value { - <> + <> } class Size { } class CSSString { } class PrimitiveValue { - <> + <> } class CSSFunction { } From e63e5a846d114f4f5cf6f38c0563b991fa82c507 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 17:50:41 +0100 Subject: [PATCH 56/63] Update phpunit/phpunit requirement from ^8.5.36 to ^8.5.37 (#519) Updates the requirements on [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) to permit the latest version. - [Changelog](https://github.com/sebastianbergmann/phpunit/blob/8.5.37/ChangeLog-8.5.md) - [Commits](https://github.com/sebastianbergmann/phpunit/compare/8.5.36...8.5.37) --- updated-dependencies: - dependency-name: phpunit/phpunit dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9a818840..f008c8fd 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "phpstan/extension-installer": "^1.3.1", "phpstan/phpstan": "^1.10.59", "phpstan/phpstan-phpunit": "^1.3.16", - "phpunit/phpunit": "^8.5.36" + "phpunit/phpunit": "^8.5.37" }, "suggest": { "ext-mbstring": "for parsing UTF-8 CSS" From ac8b039514e91743534d8619d8d243b89edf173e Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 7 Mar 2024 02:25:40 +0100 Subject: [PATCH 57/63] [TASK] Use auto-generated inheritance/implementation in the class diagram (#518) Now the only part of the class diagram which we need to maintain manually are the associations between classes. --- README.md | 77 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 116f8911..9dab4549 100644 --- a/README.md +++ b/README.md @@ -713,46 +713,47 @@ classDiagram class Comment { } - %% end of the generated part + RuleSet <|-- DeclarationBlock: inheritance + Renderable <|.. RuleSet: realization + Commentable <|.. RuleSet: realization + RuleSet <|-- AtRuleSet: inheritance + AtRule <|.. AtRuleSet: realization + Selector <|-- KeyframeSelector: inheritance + Renderable <|-- AtRule: inheritance + Commentable <|-- AtRule: inheritance + AtRule <|.. Charset: realization + AtRule <|.. Import: realization + AtRule <|.. CSSNamespace: realization + Renderable <|.. Rule: realization + Commentable <|.. Rule: realization + SourceException <|-- OutputException: inheritance + UnexpectedTokenException <|-- UnexpectedEOFException: inheritance + Exception <|-- SourceException: inheritance + SourceException <|-- UnexpectedTokenException: inheritance + CSSList <|-- CSSBlockList: inheritance + CSSBlockList <|-- Document: inheritance + Renderable <|.. CSSList: realization + Commentable <|.. CSSList: realization + CSSList <|-- KeyFrame: inheritance + AtRule <|.. KeyFrame: realization + CSSBlockList <|-- AtRuleBlockList: inheritance + AtRule <|.. AtRuleBlockList: realization + CSSFunction <|-- Color: inheritance + PrimitiveValue <|-- URL: inheritance + RuleValueList <|-- CalcRuleValueList: inheritance + Value <|-- ValueList: inheritance + CSSFunction <|-- CalcFunction: inheritance + ValueList <|-- LineName: inheritance + Renderable <|.. Value: realization + PrimitiveValue <|-- Size: inheritance + PrimitiveValue <|-- CSSString: inheritance + Value <|-- PrimitiveValue: inheritance + ValueList <|-- CSSFunction: inheritance + ValueList <|-- RuleValueList: inheritance + Renderable <|.. Comment: realization + %% end of the generated part - AtRule --|> Commentable - AtRule --|> Renderable - AtRuleBlockList --|> CSSBlockList - AtRuleBlockList ..|> AtRule - AtRuleSet --|> RuleSet - AtRuleSet ..|> AtRule - CSSBlockList --|> CSSList - CSSFunction --|> ValueList - CSSList ..|> Commentable - CSSList ..|> Renderable - CSSNamespace ..|> AtRule - CSSString --|> PrimitiveValue - CalcFunction --|> CSSFunction - CalcRuleValueList --|> RuleValueList - Charset ..|> AtRule - Color --|> CSSFunction - Comment ..|> Renderable - DeclarationBlock --|> RuleSet - Document --|> CSSBlockList - Import ..|> AtRule - KeyFrame --|> CSSList - KeyFrame ..|> AtRule - KeyframeSelector --|> Selector - LineName --|> ValueList - OutputException --|> SourceException - PrimitiveValue --|> Value - Rule ..|> Commentable - Rule ..|> Renderable - RuleSet ..|> Commentable - RuleSet ..|> Renderable - RuleValueList --|> ValueList - Size --|> PrimitiveValue - URL --|> PrimitiveValue - UnexpectedEOFException --|> UnexpectedTokenException - UnexpectedTokenException --|> SourceException - Value ..|> Renderable - ValueList --|> Value Anchor --> "1" ParserState : oParserState CSSList --> "*" CSSList : aContents From 451f83fba81e898cef9142245fbddd83d18cc447 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Mar 2024 12:52:15 +0100 Subject: [PATCH 58/63] Update phpstan/phpstan requirement from ^1.10.59 to ^1.10.60 (#523) Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.59...1.10.60) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f008c8fd..e9184ddf 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "codacy/coverage": "^1.4.3", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.59", + "phpstan/phpstan": "^1.10.60", "phpstan/phpstan-phpunit": "^1.3.16", "phpunit/phpunit": "^8.5.37" }, From 6d6d8b93e0366dd3dc9f1a5616d84d2cbfcbc55a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 12:20:13 +0100 Subject: [PATCH 59/63] Update phpstan/phpstan requirement from ^1.10.60 to ^1.10.61 (#525) Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.60...1.10.61) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e9184ddf..254bb531 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "codacy/coverage": "^1.4.3", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.60", + "phpstan/phpstan": "^1.10.61", "phpstan/phpstan-phpunit": "^1.3.16", "phpunit/phpunit": "^8.5.37" }, From 06c4aef0fce9941b5bc69a95abf75fd7144002cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:29:55 +0100 Subject: [PATCH 60/63] Update phpstan/phpstan requirement from ^1.10.61 to ^1.10.62 (#526) Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.61...1.10.62) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 254bb531..d729a1ec 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "codacy/coverage": "^1.4.3", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.61", + "phpstan/phpstan": "^1.10.62", "phpstan/phpstan-phpunit": "^1.3.16", "phpunit/phpunit": "^8.5.37" }, From f116090f91789cb356f81c4a6b50c153e6d4f80e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:46:36 +0100 Subject: [PATCH 61/63] Update phpstan/phpstan requirement from ^1.10.62 to ^1.10.63 (#527) Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.62...1.10.63) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d729a1ec..8ba247cb 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "codacy/coverage": "^1.4.3", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.62", + "phpstan/phpstan": "^1.10.63", "phpstan/phpstan-phpunit": "^1.3.16", "phpunit/phpunit": "^8.5.37" }, From 8b96b311b2deaa1b3af3f944318ba5510ac2ed6f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:03:49 +0100 Subject: [PATCH 62/63] Update phpstan/phpstan requirement from ^1.10.63 to ^1.10.64 (#529) Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.63...1.10.64) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8ba247cb..9e98ecca 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "codacy/coverage": "^1.4.3", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.63", + "phpstan/phpstan": "^1.10.64", "phpstan/phpstan-phpunit": "^1.3.16", "phpunit/phpunit": "^8.5.37" }, From eda7c2447c40bf9211c38491648db02811bf1c3c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 13:22:47 +0100 Subject: [PATCH 63/63] Update phpstan/phpstan requirement from ^1.10.64 to ^1.10.65 (#530) Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.64...1.10.65) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9e98ecca..e8e42ce9 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "require-dev": { "codacy/coverage": "^1.4.3", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.64", + "phpstan/phpstan": "^1.10.65", "phpstan/phpstan-phpunit": "^1.3.16", "phpunit/phpunit": "^8.5.37" },