From 966b11bb64f89df0db627ca98c8c4670f5637394 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 27 Feb 2025 10:47:27 +0100 Subject: [PATCH] [TASK] Make the `OutputFormat` properties private Also use the accessors as necessary. Fixes #882 --- src/CSSList/AtRuleBlockList.php | 4 +- src/OutputFormat.php | 100 ++++++++----------------------- src/OutputFormatter.php | 2 +- src/RuleSet/DeclarationBlock.php | 6 +- 4 files changed, 31 insertions(+), 81 deletions(-) diff --git a/src/CSSList/AtRuleBlockList.php b/src/CSSList/AtRuleBlockList.php index 892acfd4..577c6b8f 100644 --- a/src/CSSList/AtRuleBlockList.php +++ b/src/CSSList/AtRuleBlockList.php @@ -53,7 +53,7 @@ public function __toString(): string public function render(OutputFormat $outputFormat): string { $result = $outputFormat->comments($this); - $result .= $outputFormat->sBeforeAtRuleBlock; + $result .= $outputFormat->getBeforeAtRuleBlock(); $arguments = $this->arguments; if ($arguments) { $arguments = ' ' . $arguments; @@ -61,7 +61,7 @@ public function render(OutputFormat $outputFormat): string $result .= "@{$this->type}$arguments{$outputFormat->spaceBeforeOpeningBrace()}{"; $result .= $this->renderListContents($outputFormat); $result .= '}'; - $result .= $outputFormat->sAfterAtRuleBlock; + $result .= $outputFormat->getAfterAtRuleBlock(); return $result; } diff --git a/src/OutputFormat.php b/src/OutputFormat.php index caec89a5..30c2e8fe 100644 --- a/src/OutputFormat.php +++ b/src/OutputFormat.php @@ -10,19 +10,15 @@ class OutputFormat * Value format: `"` means double-quote, `'` means single-quote * * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $stringQuotingType = '"'; + private $stringQuotingType = '"'; /** * Output RGB colors in hash notation if possible * * @var bool - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $bRGBHashNotation = true; + private $bRGBHashNotation = true; /** * Declaration format @@ -30,10 +26,8 @@ class OutputFormat * Semicolon after the last rule of a declaration block can be omitted. To do that, set this false. * * @var bool - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $bSemicolonAfterLastRule = true; + private $bSemicolonAfterLastRule = true; /** * Spacing @@ -43,177 +37,133 @@ class OutputFormat * (e.g. `$outputFormat->set('Space*Rules', "\n");`) * * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceAfterRuleName = ' '; + private $sSpaceAfterRuleName = ' '; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceBeforeRules = ''; + private $sSpaceBeforeRules = ''; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceAfterRules = ''; + private $sSpaceAfterRules = ''; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceBetweenRules = ''; + private $sSpaceBetweenRules = ''; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceBeforeBlocks = ''; + private $sSpaceBeforeBlocks = ''; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceAfterBlocks = ''; + private $sSpaceAfterBlocks = ''; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceBetweenBlocks = "\n"; + private $sSpaceBetweenBlocks = "\n"; /** * Content injected in and around at-rule blocks. * * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sBeforeAtRuleBlock = ''; + private $sBeforeAtRuleBlock = ''; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sAfterAtRuleBlock = ''; + private $sAfterAtRuleBlock = ''; /** * This is what’s printed before and after the comma if a declaration block contains multiple selectors. * * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceBeforeSelectorSeparator = ''; + private $sSpaceBeforeSelectorSeparator = ''; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceAfterSelectorSeparator = ' '; + private $sSpaceAfterSelectorSeparator = ' '; /** * This is what’s inserted before the separator in value lists, by default. * * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceBeforeListArgumentSeparator = ''; + private $sSpaceBeforeListArgumentSeparator = ''; /** * Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string. * * @var array - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $aSpaceBeforeListArgumentSeparators = []; + private $aSpaceBeforeListArgumentSeparators = []; /** * This is what’s inserted after the separator in value lists, by default. * * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceAfterListArgumentSeparator = ''; + private $sSpaceAfterListArgumentSeparator = ''; /** * Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string. * * @var array - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $aSpaceAfterListArgumentSeparators = []; + private $aSpaceAfterListArgumentSeparators = []; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sSpaceBeforeOpeningBrace = ' '; + private $sSpaceBeforeOpeningBrace = ' '; /** * Content injected in and around declaration blocks. * * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sBeforeDeclarationBlock = ''; + private $sBeforeDeclarationBlock = ''; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sAfterDeclarationBlockSelectors = ''; + private $sAfterDeclarationBlockSelectors = ''; /** * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sAfterDeclarationBlock = ''; + private $sAfterDeclarationBlock = ''; /** * Indentation character(s) per level. Only applicable if newlines are used in any of the spacing settings. * * @var string - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sIndentation = "\t"; + private $sIndentation = "\t"; /** * Output exceptions. * * @var bool - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $bIgnoreExceptions = false; + private $bIgnoreExceptions = false; /** * Render comments for lists and RuleSets * * @var bool - * - * @internal since 8.8.0, will be made private in 9.0.0 */ - public $bRenderComments = false; + private $bRenderComments = false; /** * @var OutputFormatter|null diff --git a/src/OutputFormatter.php b/src/OutputFormatter.php index 1e39d210..7b61b0ab 100644 --- a/src/OutputFormatter.php +++ b/src/OutputFormatter.php @@ -225,6 +225,6 @@ private function prepareSpace(string $spaceString): string private function indent(): string { - return \str_repeat($this->outputFormat->sIndentation, $this->outputFormat->getIndentationLevel()); + return \str_repeat($this->outputFormat->getIndentation(), $this->outputFormat->getIndentationLevel()); } } diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index 7e0dfc1b..6ebf9402 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -160,16 +160,16 @@ public function render(OutputFormat $outputFormat): string // If all the selectors have been removed, this declaration block becomes invalid throw new OutputException('Attempt to print declaration block with missing selector', $this->lineNumber); } - $result .= $outputFormat->sBeforeDeclarationBlock; + $result .= $outputFormat->getBeforeDeclarationBlock(); $result .= $outputFormat->implode( $outputFormat->spaceBeforeSelectorSeparator() . ',' . $outputFormat->spaceAfterSelectorSeparator(), $this->selectors ); - $result .= $outputFormat->sAfterDeclarationBlockSelectors; + $result .= $outputFormat->getAfterDeclarationBlockSelectors(); $result .= $outputFormat->spaceBeforeOpeningBrace() . '{'; $result .= $this->renderRules($outputFormat); $result .= '}'; - $result .= $outputFormat->sAfterDeclarationBlock; + $result .= $outputFormat->getAfterDeclarationBlock(); return $result; } }