Skip to content

Commit 595da81

Browse files
committed
[TASK] Deprecate __toString()
Part of #998
1 parent 215c199 commit 595da81

25 files changed

+88
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Please also have a look at our
3232

3333
### Deprecated
3434

35+
- Deprecate `__toString()` (#1006)
3536
- `OutputFormat` properties for space around list separators as an array (#880)
3637

3738
### Removed

src/CSSList/AtRuleBlockList.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function atRuleArgs(): string
4242
return $this->arguments;
4343
}
4444

45+
/**
46+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
47+
*/
4548
public function __toString(): string
4649
{
4750
return $this->render(new OutputFormat());

src/CSSList/CSSList.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ public function removeDeclarationBlockBySelector($selectors, $removeAll = false)
402402
}
403403
}
404404

405+
/**
406+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
407+
*/
405408
public function __toString(): string
406409
{
407410
return $this->render(new OutputFormat());

src/CSSList/KeyFrame.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function getAnimationName()
5151
return $this->animationName;
5252
}
5353

54+
/**
55+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
56+
*/
5457
public function __toString(): string
5558
{
5659
return $this->render(new OutputFormat());

src/Comment/Comment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public function setComment(string $commentText): void
5050
$this->commentText = $commentText;
5151
}
5252

53+
/**
54+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
55+
*/
5356
public function __toString(): string
5457
{
5558
return $this->render(new OutputFormat());

src/OutputFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function safely(callable $callable): ?string
159159
}
160160

161161
/**
162-
* Clone of the `implode` function, but calls `render` with the current output format instead of `__toString()`.
162+
* Clone of the `implode` function, but calls `render` with the current output format.
163163
*
164164
* @param array<array-key, Renderable|string> $values
165165
*/

src/Property/CSSNamespace.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public function getLineNo(): int
5454
return $this->lineNumber;
5555
}
5656

57+
/**
58+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
59+
*/
5760
public function __toString(): string
5861
{
5962
return $this->render(new OutputFormat());

src/Property/Charset.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public function getCharset()
7171
return $this->charset->getString();
7272
}
7373

74+
/**
75+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
76+
*/
7477
public function __toString(): string
7578
{
7679
return $this->render(new OutputFormat());

src/Property/Import.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function getLocation()
7272
return $this->location;
7373
}
7474

75+
/**
76+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
77+
*/
7578
public function __toString(): string
7679
{
7780
return $this->render(new OutputFormat());

src/Property/Selector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ public function setSelector($selector): void
113113
$this->specificity = null;
114114
}
115115

116+
/**
117+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
118+
*/
116119
public function __toString(): string
117120
{
118121
return $this->getSelector();

src/Renderable.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
interface Renderable
88
{
9+
/**
10+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
11+
*/
912
public function __toString(): string;
1013

1114
public function render(OutputFormat $outputFormat): string;

src/Rule/Rule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ public function getIsImportant()
260260
return $this->isImportant;
261261
}
262262

263+
/**
264+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
265+
*/
263266
public function __toString(): string
264267
{
265268
return $this->render(new OutputFormat());

src/RuleSet/AtRuleSet.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function atRuleArgs()
5353
return $this->arguments;
5454
}
5555

56+
/**
57+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
58+
*/
5659
public function __toString(): string
5760
{
5861
return $this->render(new OutputFormat());

src/RuleSet/DeclarationBlock.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public function getSelectors()
142142

143143
/**
144144
* @throws OutputException
145+
*
146+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
145147
*/
146148
public function __toString(): string
147149
{

src/RuleSet/RuleSet.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ public function removeRule($mRule): void
255255
}
256256
}
257257

258+
/**
259+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
260+
*/
258261
public function __toString(): string
259262
{
260263
return $this->render(new OutputFormat());

src/Value/CSSFunction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public function getArguments()
105105
return $this->aComponents;
106106
}
107107

108+
/**
109+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
110+
*/
108111
public function __toString(): string
109112
{
110113
return $this->render(new OutputFormat());

src/Value/CSSString.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public function getString()
9090
return $this->string;
9191
}
9292

93+
/**
94+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
95+
*/
9396
public function __toString(): string
9497
{
9598
return $this->render(new OutputFormat());

src/Value/Color.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ public function getColorDescription()
224224
return $this->getName();
225225
}
226226

227+
/**
228+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
229+
*/
227230
public function __toString(): string
228231
{
229232
return $this->render(new OutputFormat());

src/Value/LineName.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public static function parse(ParserState $parserState): LineName
4949
return new LineName($aNames, $parserState->currentLine());
5050
}
5151

52+
/**
53+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
54+
*/
5255
public function __toString(): string
5356
{
5457
return $this->render(new OutputFormat());

src/Value/Size.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ public function isRelative(): bool
210210
return false;
211211
}
212212

213+
/**
214+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
215+
*/
213216
public function __toString(): string
214217
{
215218
return $this->render(new OutputFormat());

src/Value/URL.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function getURL()
7676
return $this->oURL;
7777
}
7878

79+
/**
80+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
81+
*/
7982
public function __toString(): string
8083
{
8184
return $this->render(new OutputFormat());

src/Value/ValueList.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public function setListSeparator($sSeparator): void
8383
$this->sSeparator = $sSeparator;
8484
}
8585

86+
/**
87+
* @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
88+
*/
8689
public function __toString(): string
8790
{
8891
return $this->render(new OutputFormat());

tests/Functional/Comment/CommentTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,6 @@
1313
*/
1414
final class CommentTest extends TestCase
1515
{
16-
/**
17-
* @test
18-
*/
19-
public function toStringRendersCommentEnclosedInCommentDelimiters(): void
20-
{
21-
$comment = 'There is no spoon.';
22-
$subject = new Comment();
23-
24-
$subject->setComment($comment);
25-
26-
self::assertSame('/*' . $comment . '*/', (string) $subject);
27-
}
28-
2916
/**
3017
* @test
3118
*/

tests/FunctionalDeprecated/.gitkeep

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sabberworm\CSS\Tests\FunctionalDeprecated\Comment;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Sabberworm\CSS\Comment\Comment;
9+
10+
/**
11+
* @covers \Sabberworm\CSS\Comment\Comment
12+
*/
13+
final class CommentTest extends TestCase
14+
{
15+
/**
16+
* @test
17+
*/
18+
public function toStringRendersCommentEnclosedInCommentDelimiters(): void
19+
{
20+
$comment = 'There is no spoon.';
21+
$subject = new Comment();
22+
23+
$subject->setComment($comment);
24+
25+
self::assertSame('/*' . $comment . '*/', (string) $subject);
26+
}
27+
}

0 commit comments

Comments
 (0)