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
76 changes: 74 additions & 2 deletions src/OutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@

class OutputFormatter
{
/**
* @var OutputFormat
*/
private $oFormat;

public function __construct(OutputFormat $oFormat)
{
$this->oFormat = $oFormat;
}

/**
* @param string $sName
* @param string|null $sType
*
* @return string
*/
public function space($sName, $sType = null)
{
$sSpaceString = $this->oFormat->get("Space$sName");
Expand All @@ -28,68 +37,112 @@ public function space($sName, $sType = null)
return $this->prepareSpace($sSpaceString);
}

/**
* @return string
*/
public function spaceAfterRuleName()
{
return $this->space('AfterRuleName');
}

/**
* @return string
*/
public function spaceBeforeRules()
{
return $this->space('BeforeRules');
}

/**
* @return string
*/
public function spaceAfterRules()
{
return $this->space('AfterRules');
}

/**
* @return string
*/
public function spaceBetweenRules()
{
return $this->space('BetweenRules');
}

/**
* @return string
*/
public function spaceBeforeBlocks()
{
return $this->space('BeforeBlocks');
}

/**
* @return string
*/
public function spaceAfterBlocks()
{
return $this->space('AfterBlocks');
}

/**
* @return string
*/
public function spaceBetweenBlocks()
{
return $this->space('BetweenBlocks');
}

/**
* @return string
*/
public function spaceBeforeSelectorSeparator()
{
return $this->space('BeforeSelectorSeparator');
}

/**
* @return string
*/
public function spaceAfterSelectorSeparator()
{
return $this->space('AfterSelectorSeparator');
}

/**
* @param string $sSeparator
*
* @return string
*/
public function spaceBeforeListArgumentSeparator($sSeparator)
{
return $this->space('BeforeListArgumentSeparator', $sSeparator);
}

/**
* @param string $sSeparator
*
* @return string
*/
public function spaceAfterListArgumentSeparator($sSeparator)
{
return $this->space('AfterListArgumentSeparator', $sSeparator);
}

/**
* @return string
*/
public function spaceBeforeOpeningBrace()
{
return $this->space('BeforeOpeningBrace');
}

/**
* Runs the given code, either swallowing or passing exceptions, depending on the bIgnoreExceptions setting.
* Runs the given code, either swallowing or passing exceptions, depending on the `bIgnoreExceptions` setting.
*
* @param string $cCode the name of the function to call
*
* @return string|null
*/
public function safely($cCode)
{
Expand All @@ -107,7 +160,13 @@ public function safely($cCode)
}

/**
* Clone of the implode function but calls -> render with the current output format instead of `__toString()`
* Clone of the `implode` function, but calls `render` with the current output format instead of `__toString()`.
*
* @param string $sSeparator
* @param array<array-key, Renderable|string> $aValues
* @param bool $bIncreaseLevel
*
* @return string
*/
public function implode($sSeparator, array $aValues, $bIncreaseLevel = false)
{
Expand All @@ -132,6 +191,11 @@ public function implode($sSeparator, array $aValues, $bIncreaseLevel = false)
return $sResult;
}

/**
* @param string $sString
*
* @return string
*/
public function removeLastSemicolon($sString)
{
if ($this->oFormat->get('SemicolonAfterLastRule')) {
Expand All @@ -147,11 +211,19 @@ public function removeLastSemicolon($sString)
return implode(';', $sString);
}

/**
* @param string $sSpaceString
*
* @return string
*/
private function prepareSpace($sSpaceString)
{
return str_replace("\n", "\n" . $this->indent(), $sSpaceString);
}

/**
* @return string
*/
private function indent()
{
return str_repeat($this->oFormat->sIndentation, $this->oFormat->level());
Expand Down