Skip to content
Merged
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
68 changes: 52 additions & 16 deletions src/OutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,54 @@ public function __construct(OutputFormat $outputFormat)
$this->outputFormat = $outputFormat;
}

public function space(string $sName, ?string $sType = null): string
{
$sSpaceString = $this->outputFormat->get("Space$sName");
// If $sSpaceString is an array, we have multiple values configured
// depending on the type of object the space applies to
if (\is_array($sSpaceString)) {
if ($sType !== null && isset($sSpaceString[$sType])) {
$sSpaceString = $sSpaceString[$sType];
} else {
$sSpaceString = \reset($sSpaceString);
}
/**
* @param non-empty-string $sName
*
* @throws \InvalidArgumentException
*/
public function space(string $sName): string
{
switch ($sName) {
case 'AfterRuleName':
$sSpaceString = $this->outputFormat->getSpaceAfterRuleName();
break;
case 'BeforeRules':
$sSpaceString = $this->outputFormat->getSpaceBeforeRules();
break;
case 'AfterRules':
$sSpaceString = $this->outputFormat->getSpaceAfterRules();
break;
case 'BetweenRules':
$sSpaceString = $this->outputFormat->getSpaceBetweenRules();
break;
case 'BeforeBlocks':
$sSpaceString = $this->outputFormat->getSpaceBeforeBlocks();
break;
case 'AfterBlocks':
$sSpaceString = $this->outputFormat->getSpaceAfterBlocks();
break;
case 'BetweenBlocks':
$sSpaceString = $this->outputFormat->getSpaceBetweenBlocks();
break;
case 'BeforeSelectorSeparator':
$sSpaceString = $this->outputFormat->getSpaceBeforeSelectorSeparator();
break;
case 'AfterSelectorSeparator':
$sSpaceString = $this->outputFormat->getSpaceAfterSelectorSeparator();
break;
case 'BeforeOpeningBrace':
$sSpaceString = $this->outputFormat->getSpaceBeforeOpeningBrace();
break;
case 'BeforeListArgumentSeparator':
$sSpaceString = $this->outputFormat->getSpaceBeforeListArgumentSeparator();
break;
case 'AfterListArgumentSeparator':
$sSpaceString = $this->outputFormat->getSpaceAfterListArgumentSeparator();
break;
default:
throw new \InvalidArgumentException("Unknown space type: $sName", 1740049248);
}

return $this->prepareSpace($sSpaceString);
}

Expand Down Expand Up @@ -86,7 +122,7 @@ public function spaceBeforeListArgumentSeparator(string $sSeparator): string
{
$spaceForSeparator = $this->outputFormat->getSpaceBeforeListArgumentSeparators();

return $spaceForSeparator[$sSeparator] ?? $this->space('BeforeListArgumentSeparator', $sSeparator);
return $spaceForSeparator[$sSeparator] ?? $this->space('BeforeListArgumentSeparator');
}

/**
Expand All @@ -96,7 +132,7 @@ public function spaceAfterListArgumentSeparator(string $sSeparator): string
{
$spaceForSeparator = $this->outputFormat->getSpaceAfterListArgumentSeparators();

return $spaceForSeparator[$sSeparator] ?? $this->space('AfterListArgumentSeparator', $sSeparator);
return $spaceForSeparator[$sSeparator] ?? $this->space('AfterListArgumentSeparator');
}

public function spaceBeforeOpeningBrace(): string
Expand All @@ -109,7 +145,7 @@ public function spaceBeforeOpeningBrace(): string
*/
public function safely(callable $cCode): ?string
{
if ($this->outputFormat->get('IgnoreExceptions')) {
if ($this->outputFormat->getIgnoreExceptions()) {
// If output exceptions are ignored, run the code with exception guards
try {
return $cCode();
Expand Down Expand Up @@ -152,7 +188,7 @@ public function implode(string $sSeparator, array $aValues, bool $bIncreaseLevel

public function removeLastSemicolon(string $sString): string
{
if ($this->outputFormat->get('SemicolonAfterLastRule')) {
if ($this->outputFormat->getSemicolonAfterLastRule()) {
return $sString;
}
$sString = \explode(';', $sString);
Expand All @@ -167,7 +203,7 @@ public function removeLastSemicolon(string $sString): string

public function comments(Commentable $oCommentable): string
{
if (!$this->outputFormat->bRenderComments) {
if (!$this->outputFormat->getRenderComments()) {
return '';
}

Expand Down