Skip to content

[TASK] Make the OutputFormat properties private #1014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/CSSList/AtRuleBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ 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;
}
$result .= "@{$this->type}$arguments{$outputFormat->spaceBeforeOpeningBrace()}{";
$result .= $this->renderListContents($outputFormat);
$result .= '}';
$result .= $outputFormat->sAfterAtRuleBlock;
$result .= $outputFormat->getAfterAtRuleBlock();
return $result;
}

Expand Down
100 changes: 25 additions & 75 deletions src/OutputFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,24 @@ 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
*
* 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
Expand All @@ -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<non-empty-string, string>
*
* @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<non-empty-string, string>
*
* @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
Expand Down
2 changes: 1 addition & 1 deletion src/OutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
6 changes: 3 additions & 3 deletions src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}