From 45340b2543802357180834dd9c33834806858061 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 27 Feb 2025 11:44:18 +0100 Subject: [PATCH] [TASK] Remove `__toString()` Part of #998. --- src/CSSList/AtRuleBlockList.php | 8 ------ src/CSSList/CSSList.php | 8 ------ src/CSSList/KeyFrame.php | 8 ------ src/Comment/Comment.php | 8 ------ src/Property/CSSNamespace.php | 8 ------ src/Property/Charset.php | 8 ------ src/Property/Import.php | 8 ------ src/Property/Selector.php | 8 ------ src/Renderable.php | 5 ---- src/Rule/Rule.php | 8 ------ src/RuleSet/AtRuleSet.php | 8 ------ src/RuleSet/DeclarationBlock.php | 10 ------- src/RuleSet/RuleSet.php | 8 ------ src/Value/CSSFunction.php | 8 ------ src/Value/CSSString.php | 8 ------ src/Value/Color.php | 8 ------ src/Value/LineName.php | 8 ------ src/Value/Size.php | 8 ------ src/Value/URL.php | 8 ------ src/Value/ValueList.php | 8 ------ tests/FunctionalDeprecated/.gitkeep | 0 .../Comment/CommentTest.php | 27 ------------------- .../Property/SelectorTest.php | 25 ----------------- tests/ParserTest.php | 2 +- tests/Unit/Value/ColorTest.php | 3 ++- tests/Unit/Value/ValueTest.php | 17 +++++++++--- 26 files changed, 17 insertions(+), 216 deletions(-) create mode 100644 tests/FunctionalDeprecated/.gitkeep delete mode 100644 tests/FunctionalDeprecated/Comment/CommentTest.php delete mode 100644 tests/FunctionalDeprecated/Property/SelectorTest.php diff --git a/src/CSSList/AtRuleBlockList.php b/src/CSSList/AtRuleBlockList.php index 577c6b8fc..9287da4ff 100644 --- a/src/CSSList/AtRuleBlockList.php +++ b/src/CSSList/AtRuleBlockList.php @@ -42,14 +42,6 @@ public function atRuleArgs(): string return $this->arguments; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { $result = $outputFormat->comments($this); diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index cfc5d7bbc..8c40990b6 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -402,14 +402,6 @@ public function removeDeclarationBlockBySelector($selectors, $removeAll = false) } } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - /** * @return string */ diff --git a/src/CSSList/KeyFrame.php b/src/CSSList/KeyFrame.php index 3177ac19c..a9611fe2e 100644 --- a/src/CSSList/KeyFrame.php +++ b/src/CSSList/KeyFrame.php @@ -51,14 +51,6 @@ public function getAnimationName() return $this->animationName; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { $result = $outputFormat->comments($this); diff --git a/src/Comment/Comment.php b/src/Comment/Comment.php index 761d6d824..e96bd28ee 100644 --- a/src/Comment/Comment.php +++ b/src/Comment/Comment.php @@ -50,14 +50,6 @@ public function setComment(string $commentText): void $this->commentText = $commentText; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { return '/*' . $this->commentText . '*/'; diff --git a/src/Property/CSSNamespace.php b/src/Property/CSSNamespace.php index 7a4f64a90..7dcabba04 100644 --- a/src/Property/CSSNamespace.php +++ b/src/Property/CSSNamespace.php @@ -54,14 +54,6 @@ public function getLineNo(): int return $this->lineNumber; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { return '@namespace ' . ($this->prefix === null ? '' : $this->prefix . ' ') diff --git a/src/Property/Charset.php b/src/Property/Charset.php index dea13e16c..bf5ac9f40 100644 --- a/src/Property/Charset.php +++ b/src/Property/Charset.php @@ -71,14 +71,6 @@ public function getCharset() return $this->charset->getString(); } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { return "{$outputFormat->comments($this)}@charset {$this->charset->render($outputFormat)};"; diff --git a/src/Property/Import.php b/src/Property/Import.php index 520e01209..7174c160c 100644 --- a/src/Property/Import.php +++ b/src/Property/Import.php @@ -72,14 +72,6 @@ public function getLocation() return $this->location; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { return $outputFormat->comments($this) . '@import ' . $this->location->render($outputFormat) diff --git a/src/Property/Selector.php b/src/Property/Selector.php index f1bbbcefb..1d727047d 100644 --- a/src/Property/Selector.php +++ b/src/Property/Selector.php @@ -61,14 +61,6 @@ public function setSelector(string $selector): void $this->selector = \trim($selector); } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->getSelector(); - } - /** * @return int<0, max> */ diff --git a/src/Renderable.php b/src/Renderable.php index ed6336544..9ebf9a9b9 100644 --- a/src/Renderable.php +++ b/src/Renderable.php @@ -6,10 +6,5 @@ interface Renderable { - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string; - public function render(OutputFormat $outputFormat): string; } diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index 0ec26902a..d686db85d 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -224,14 +224,6 @@ public function getIsImportant() return $this->isImportant; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { $result = "{$outputFormat->comments($this)}{$this->rule}:{$outputFormat->spaceAfterRuleName()}"; diff --git a/src/RuleSet/AtRuleSet.php b/src/RuleSet/AtRuleSet.php index 9f7a17058..34b538569 100644 --- a/src/RuleSet/AtRuleSet.php +++ b/src/RuleSet/AtRuleSet.php @@ -53,14 +53,6 @@ public function atRuleArgs() return $this->arguments; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { $result = $outputFormat->comments($this); diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index 5f914d1d1..b38bc11dc 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -140,16 +140,6 @@ public function getSelectors() return $this->selectors; } - /** - * @throws OutputException - * - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - /** * @throws OutputException */ diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index 42f7878e3..322f00865 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -255,14 +255,6 @@ public function removeRule($searchPattern): void } } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - /** * @return string */ diff --git a/src/Value/CSSFunction.php b/src/Value/CSSFunction.php index b32c9c2fa..a6104d31d 100644 --- a/src/Value/CSSFunction.php +++ b/src/Value/CSSFunction.php @@ -105,14 +105,6 @@ public function getArguments() return $this->aComponents; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { $aArguments = parent::render($outputFormat); diff --git a/src/Value/CSSString.php b/src/Value/CSSString.php index 8f87c6e1c..75485d35b 100644 --- a/src/Value/CSSString.php +++ b/src/Value/CSSString.php @@ -90,14 +90,6 @@ public function getString() return $this->string; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { $string = \addslashes($this->string); diff --git a/src/Value/Color.php b/src/Value/Color.php index 81cd75540..fc34a1a40 100644 --- a/src/Value/Color.php +++ b/src/Value/Color.php @@ -224,14 +224,6 @@ public function getColorDescription() return $this->getName(); } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { if ($this->shouldRenderAsHex($outputFormat)) { diff --git a/src/Value/LineName.php b/src/Value/LineName.php index 379aae874..efc1109dd 100644 --- a/src/Value/LineName.php +++ b/src/Value/LineName.php @@ -49,14 +49,6 @@ public static function parse(ParserState $parserState): LineName return new LineName($aNames, $parserState->currentLine()); } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { return '[' . parent::render(OutputFormat::createCompact()) . ']'; diff --git a/src/Value/Size.php b/src/Value/Size.php index 36a2ac6ee..51e95a22a 100644 --- a/src/Value/Size.php +++ b/src/Value/Size.php @@ -210,14 +210,6 @@ public function isRelative(): bool return false; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { $l = \localeconv(); diff --git a/src/Value/URL.php b/src/Value/URL.php index 15eb52e02..2bdf10f31 100644 --- a/src/Value/URL.php +++ b/src/Value/URL.php @@ -76,14 +76,6 @@ public function getURL() return $this->oURL; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { return "url({$this->oURL->render($outputFormat)})"; diff --git a/src/Value/ValueList.php b/src/Value/ValueList.php index 5c7b8f84b..575094f49 100644 --- a/src/Value/ValueList.php +++ b/src/Value/ValueList.php @@ -83,14 +83,6 @@ public function setListSeparator($sSeparator): void $this->sSeparator = $sSeparator; } - /** - * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead. - */ - public function __toString(): string - { - return $this->render(new OutputFormat()); - } - public function render(OutputFormat $outputFormat): string { return $outputFormat->implode( diff --git a/tests/FunctionalDeprecated/.gitkeep b/tests/FunctionalDeprecated/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/FunctionalDeprecated/Comment/CommentTest.php b/tests/FunctionalDeprecated/Comment/CommentTest.php deleted file mode 100644 index 8d9c1d317..000000000 --- a/tests/FunctionalDeprecated/Comment/CommentTest.php +++ /dev/null @@ -1,27 +0,0 @@ -setComment($comment); - - self::assertSame('/*' . $comment . '*/', (string) $subject); - } -} diff --git a/tests/FunctionalDeprecated/Property/SelectorTest.php b/tests/FunctionalDeprecated/Property/SelectorTest.php deleted file mode 100644 index 917d227ff..000000000 --- a/tests/FunctionalDeprecated/Property/SelectorTest.php +++ /dev/null @@ -1,25 +0,0 @@ -getRules('content'); - $firstContentRuleAsString = $contentRules[0]->getValue()->__toString(); + $firstContentRuleAsString = $contentRules[0]->getValue()->render(OutputFormat::create()); if ($selector === '.test-1') { self::assertSame('" "', $firstContentRuleAsString); } diff --git a/tests/Unit/Value/ColorTest.php b/tests/Unit/Value/ColorTest.php index f516d3134..aaa257553 100644 --- a/tests/Unit/Value/ColorTest.php +++ b/tests/Unit/Value/ColorTest.php @@ -5,6 +5,7 @@ namespace Sabberworm\CSS\Tests\Unit\Value; use PHPUnit\Framework\TestCase; +use Sabberworm\CSS\OutputFormat; use Sabberworm\CSS\Parsing\ParserState; use Sabberworm\CSS\Parsing\SourceException; use Sabberworm\CSS\Settings; @@ -346,7 +347,7 @@ public function parsesAndRendersValidColor(string $color, string $expectedRender { $subject = Color::parse(new ParserState($color, Settings::create())); - $renderedResult = (string) $subject; + $renderedResult = $subject->render(OutputFormat::create()); self::assertSame($expectedRendering, $renderedResult); } diff --git a/tests/Unit/Value/ValueTest.php b/tests/Unit/Value/ValueTest.php index 380a2ebb5..4208a2055 100644 --- a/tests/Unit/Value/ValueTest.php +++ b/tests/Unit/Value/ValueTest.php @@ -5,8 +5,10 @@ namespace Sabberworm\CSS\Tests\Unit\Value; use PHPUnit\Framework\TestCase; +use Sabberworm\CSS\OutputFormat; use Sabberworm\CSS\Parsing\ParserState; use Sabberworm\CSS\Settings; +use Sabberworm\CSS\Value\CSSFunction; use Sabberworm\CSS\Value\Value; /** @@ -53,7 +55,8 @@ public function parsesArithmeticInFunctions(string $operator): void self::DEFAULT_DELIMITERS ); - self::assertSame('max(300px,50vh ' . $operator . ' 10px)', (string) $subject); + self::assertInstanceOf(CSSFunction::class, $subject); + self::assertSame('max(300px,50vh ' . $operator . ' 10px)', $subject->render(OutputFormat::createCompact())); } /** @@ -95,7 +98,11 @@ public function parsesArithmeticWithMultipleOperatorsInFunctions( self::DEFAULT_DELIMITERS ); - self::assertSame(\sprintf($expectedResultTemplate, $expression), (string) $subject); + self::assertInstanceOf(CSSFunction::class, $subject); + self::assertSame( + \sprintf($expectedResultTemplate, $expression), + $subject->render(OutputFormat::createCompact()) + ); } /** @@ -123,6 +130,10 @@ public function parsesArithmeticWithMalformedOperandsInFunctions(string $leftOpe self::DEFAULT_DELIMITERS ); - self::assertSame('max(300px,' . $leftOperand . ' + ' . $rightOperand . ')', (string) $subject); + self::assertInstanceOf(CSSFunction::class, $subject); + self::assertSame( + 'max(300px,' . $leftOperand . ' + ' . $rightOperand . ')', + $subject->render(OutputFormat::createCompact()) + ); } }