From 814d92310630c4e84b62cf3301570b146baf1b4e Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Tue, 18 Jun 2024 10:24:02 +0200 Subject: [PATCH 1/5] [CLEANUP] Deprecate DeclarationBlock::expandShorthands The `expandShorthands`/`createShorthands` Functions are deprecated and will be removed without substitution in version 10.0. Expanding and creating the shorthand notation is out of the scope of this library. If you want to include this functionality in your project or build it into a separate package, get the code from the v8.5.1 version of this library. Signed-off-by: Daniel Ziegenberg --- CHANGELOG.md | 2 ++ README.md | 4 ++++ src/RuleSet/DeclarationBlock.php | 10 ++++------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f31a4a61d..186f382f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Deprecated +- `DeclarationBlock::expandShorthands()` is deprecated and will be removed without substitution in version 10.0. + ### Removed - Drop support for PHP < 7.2 (#420) diff --git a/README.md b/README.md index 9dab4549f..4eb976114 100644 --- a/README.md +++ b/README.md @@ -801,6 +801,10 @@ classDiagram The latest pre-PSR-0 version of this project can be checked with the `0.9.0` tag. +The `expandShorthands`/`createShorthands` Functions are deprecated and will be removed without substitution in version 10.0. +Expanding and creating the shorthand notation is out of the scope of this library. If you want to include this functionality +in your project or build it into a separate package, get the code from the v8.5.1 version of this library. + ### Running Tests To run all continuous integration (CI) checks for this project (including unit tests), diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index 237167240..8b484b7fe 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -181,15 +181,13 @@ public function getSelectors() * Splits shorthand declarations (e.g. `margin` or `font`) into their constituent parts. * * @return void + * + * @deprecated This will be removed without substitution in version 10.0. */ public function expandShorthands() { - // border must be expanded before dimensions - $this->expandBorderShorthand(); - $this->expandDimensionsShorthand(); - $this->expandFontShorthand(); - $this->expandBackgroundShorthand(); - $this->expandListStyleShorthand(); + trigger_error("Expanding Shorthands will be removed without substitution in version 10.0."); + return; } /** From c7351adb8e2ebd84cdf7bcd739673f1900369521 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Tue, 18 Jun 2024 11:22:17 +0200 Subject: [PATCH 2/5] [CLEANUP] Fix tests after deprecating DeclarationBlock::expandShorthands Signed-off-by: Daniel Ziegenberg --- tests/ParserTest.php | 24 ---------------------- tests/RuleSet/DeclarationBlockTest.php | 28 -------------------------- 2 files changed, 52 deletions(-) diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 91cd283cc..c12a2743b 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -490,30 +490,6 @@ public function functionSyntax(): void self::assertSame($sExpected, $oDoc->render()); } - /** - * @test - */ - public function expandShorthands(): void - { - $oDoc = self::parsedStructureForFile('expand-shorthands'); - $sExpected = 'body {font: italic 500 14px/1.618 "Trebuchet MS",Georgia,serif;border: 2px solid #f0f;' - . 'background: #ccc url("/images/foo.png") no-repeat left top;margin: 1em !important;' - . 'padding: 2px 6px 3px;}'; - self::assertSame($sExpected, $oDoc->render()); - $oDoc->expandShorthands(); - $sExpected = 'body {margin-top: 1em !important;margin-right: 1em !important;margin-bottom: 1em !important;' - . 'margin-left: 1em !important;padding-top: 2px;padding-right: 6px;padding-bottom: 3px;' - . 'padding-left: 6px;border-top-color: #f0f;border-right-color: #f0f;border-bottom-color: #f0f;' - . 'border-left-color: #f0f;border-top-style: solid;border-right-style: solid;' - . 'border-bottom-style: solid;border-left-style: solid;border-top-width: 2px;' - . 'border-right-width: 2px;border-bottom-width: 2px;border-left-width: 2px;font-style: italic;' - . 'font-variant: normal;font-weight: 500;font-size: 14px;line-height: 1.618;' - . 'font-family: "Trebuchet MS",Georgia,serif;background-color: #ccc;' - . 'background-image: url("/images/foo.png");background-repeat: no-repeat;background-attachment: scroll;' - . 'background-position: left top;}'; - self::assertSame($sExpected, $oDoc->render()); - } - /** * @test */ diff --git a/tests/RuleSet/DeclarationBlockTest.php b/tests/RuleSet/DeclarationBlockTest.php index ca10d229d..3ed011529 100644 --- a/tests/RuleSet/DeclarationBlockTest.php +++ b/tests/RuleSet/DeclarationBlockTest.php @@ -422,32 +422,4 @@ public function ruleInsertion(): void $oDoc->render() ); } - - /** - * @test - * - * TODO: The order is different on PHP 5.6 than on PHP >= 7.0. - */ - public function orderOfElementsMatchingOriginalOrderAfterExpandingShorthands(): void - { - $sCss = '.rule{padding:5px;padding-top: 20px}'; - $oParser = new Parser($sCss); - $oDoc = $oParser->parse(); - $aDocs = $oDoc->getAllDeclarationBlocks(); - - self::assertCount(1, $aDocs); - - $oDeclaration = array_pop($aDocs); - $oDeclaration->expandShorthands(); - - self::assertEquals( - [ - 'padding-top' => 'padding-top: 20px;', - 'padding-right' => 'padding-right: 5px;', - 'padding-bottom' => 'padding-bottom: 5px;', - 'padding-left' => 'padding-left: 5px;', - ], - array_map('strval', $oDeclaration->getRulesAssoc()) - ); - } } From c6136bd58fd8fbb3cdfbaa7b339572a5cb0b69f7 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Tue, 18 Jun 2024 17:37:57 +0200 Subject: [PATCH 3/5] fixup! [CLEANUP] Deprecate DeclarationBlock::expandShorthands --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 186f382f4..03ddaea49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Deprecated -- `DeclarationBlock::expandShorthands()` is deprecated and will be removed without substitution in version 10.0. +- Deprecate `DeclarationBlock::expandShorthands()` (#558) ### Removed From 42a077b14ab57a3b7884893e9aa2ed2b46c1767f Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Tue, 18 Jun 2024 17:40:58 +0200 Subject: [PATCH 4/5] Partly revert "[CLEANUP] Deprecate DeclarationBlock::expandShorthands" This partly reverts commit 814d92310630c4e84b62cf3301570b146baf1b4e. --- README.md | 4 ---- src/RuleSet/DeclarationBlock.php | 8 ++++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4eb976114..9dab4549f 100644 --- a/README.md +++ b/README.md @@ -801,10 +801,6 @@ classDiagram The latest pre-PSR-0 version of this project can be checked with the `0.9.0` tag. -The `expandShorthands`/`createShorthands` Functions are deprecated and will be removed without substitution in version 10.0. -Expanding and creating the shorthand notation is out of the scope of this library. If you want to include this functionality -in your project or build it into a separate package, get the code from the v8.5.1 version of this library. - ### Running Tests To run all continuous integration (CI) checks for this project (including unit tests), diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index 8b484b7fe..85ca51447 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -186,8 +186,12 @@ public function getSelectors() */ public function expandShorthands() { - trigger_error("Expanding Shorthands will be removed without substitution in version 10.0."); - return; + // border must be expanded before dimensions + $this->expandBorderShorthand(); + $this->expandDimensionsShorthand(); + $this->expandFontShorthand(); + $this->expandBackgroundShorthand(); + $this->expandListStyleShorthand(); } /** From 90482741883fb7e572237231a88fa4725bcad658 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Tue, 18 Jun 2024 17:41:45 +0200 Subject: [PATCH 5/5] Revert "[CLEANUP] Fix tests after deprecating DeclarationBlock::expandShorthands" This reverts commit c7351adb8e2ebd84cdf7bcd739673f1900369521. --- tests/ParserTest.php | 24 ++++++++++++++++++++++ tests/RuleSet/DeclarationBlockTest.php | 28 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tests/ParserTest.php b/tests/ParserTest.php index c12a2743b..91cd283cc 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -490,6 +490,30 @@ public function functionSyntax(): void self::assertSame($sExpected, $oDoc->render()); } + /** + * @test + */ + public function expandShorthands(): void + { + $oDoc = self::parsedStructureForFile('expand-shorthands'); + $sExpected = 'body {font: italic 500 14px/1.618 "Trebuchet MS",Georgia,serif;border: 2px solid #f0f;' + . 'background: #ccc url("/images/foo.png") no-repeat left top;margin: 1em !important;' + . 'padding: 2px 6px 3px;}'; + self::assertSame($sExpected, $oDoc->render()); + $oDoc->expandShorthands(); + $sExpected = 'body {margin-top: 1em !important;margin-right: 1em !important;margin-bottom: 1em !important;' + . 'margin-left: 1em !important;padding-top: 2px;padding-right: 6px;padding-bottom: 3px;' + . 'padding-left: 6px;border-top-color: #f0f;border-right-color: #f0f;border-bottom-color: #f0f;' + . 'border-left-color: #f0f;border-top-style: solid;border-right-style: solid;' + . 'border-bottom-style: solid;border-left-style: solid;border-top-width: 2px;' + . 'border-right-width: 2px;border-bottom-width: 2px;border-left-width: 2px;font-style: italic;' + . 'font-variant: normal;font-weight: 500;font-size: 14px;line-height: 1.618;' + . 'font-family: "Trebuchet MS",Georgia,serif;background-color: #ccc;' + . 'background-image: url("/images/foo.png");background-repeat: no-repeat;background-attachment: scroll;' + . 'background-position: left top;}'; + self::assertSame($sExpected, $oDoc->render()); + } + /** * @test */ diff --git a/tests/RuleSet/DeclarationBlockTest.php b/tests/RuleSet/DeclarationBlockTest.php index 3ed011529..ca10d229d 100644 --- a/tests/RuleSet/DeclarationBlockTest.php +++ b/tests/RuleSet/DeclarationBlockTest.php @@ -422,4 +422,32 @@ public function ruleInsertion(): void $oDoc->render() ); } + + /** + * @test + * + * TODO: The order is different on PHP 5.6 than on PHP >= 7.0. + */ + public function orderOfElementsMatchingOriginalOrderAfterExpandingShorthands(): void + { + $sCss = '.rule{padding:5px;padding-top: 20px}'; + $oParser = new Parser($sCss); + $oDoc = $oParser->parse(); + $aDocs = $oDoc->getAllDeclarationBlocks(); + + self::assertCount(1, $aDocs); + + $oDeclaration = array_pop($aDocs); + $oDeclaration->expandShorthands(); + + self::assertEquals( + [ + 'padding-top' => 'padding-top: 20px;', + 'padding-right' => 'padding-right: 5px;', + 'padding-bottom' => 'padding-bottom: 5px;', + 'padding-left' => 'padding-left: 5px;', + ], + array_map('strval', $oDeclaration->getRulesAssoc()) + ); + } }