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
95 changes: 89 additions & 6 deletions src/OutputFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,34 @@ class OutputFormat
*/
public $sSpaceAfterRuleName = ' ';

/**
* @var string
*/
public $sSpaceBeforeRules = '';

/**
* @var string
*/
public $sSpaceAfterRules = '';

/**
* @var string
*/
public $sSpaceBetweenRules = '';

/**
* @var string
*/
public $sSpaceBeforeBlocks = '';

/**
* @var string
*/
public $sSpaceAfterBlocks = '';

/**
* @var string
*/
public $sSpaceBetweenBlocks = "\n";

/**
Expand All @@ -60,6 +78,9 @@ class OutputFormat
*/
public $sBeforeAtRuleBlock = '';

/**
* @var string
*/
public $sAfterAtRuleBlock = '';

/**
Expand All @@ -69,6 +90,9 @@ class OutputFormat
*/
public $sSpaceBeforeSelectorSeparator = '';

/**
* @var string
*/
public $sSpaceAfterSelectorSeparator = ' ';

/**
Expand All @@ -78,8 +102,14 @@ class OutputFormat
*/
public $sSpaceBeforeListArgumentSeparator = '';

/**
* @var string
*/
public $sSpaceAfterListArgumentSeparator = '';

/**
* @var string
*/
public $sSpaceBeforeOpeningBrace = ' ';

/**
Expand All @@ -89,8 +119,14 @@ class OutputFormat
*/
public $sBeforeDeclarationBlock = '';

/**
* @var string
*/
public $sAfterDeclarationBlockSelectors = '';

/**
* @var string
*/
public $sAfterDeclarationBlock = '';

/**
Expand All @@ -107,16 +143,30 @@ class OutputFormat
*/
public $bIgnoreExceptions = false;

/**
* @var OutputFormatter|null
*/
private $oFormatter = null;

/**
* @var OutputFormat|null
*/
private $oNextLevelFormat = null;

/**
* @var int
*/
private $iIndentationLevel = 0;

public function __construct()
{
}

/**
* @param string $sName
*
* @return string|null
*/
public function get($sName)
{
$aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i'];
Expand All @@ -131,6 +181,9 @@ public function get($sName)

/**
* @param array<array-key, string>|string $aNames
* @param mixed $mValue
*
* @return self|false
*/
public function set($aNames, $mValue)
{
Expand Down Expand Up @@ -162,6 +215,14 @@ public function set($aNames, $mValue)
return false;
}

/**
* @param string $sMethodName
* @param array<array-key, mixed> $aArguments
*
* @return mixed
*
* @throws \Exception
*/
public function __call($sMethodName, array $aArguments)
{
if (strpos($sMethodName, 'set') === 0) {
Expand All @@ -175,16 +236,29 @@ public function __call($sMethodName, array $aArguments)
}
}

/**
* @param int $iNumber
*
* @return self
*/
public function indentWithTabs($iNumber = 1)
{
return $this->setIndentation(str_repeat("\t", $iNumber));
}

/**
* @param int $iNumber
*
* @return self
*/
public function indentWithSpaces($iNumber = 2)
{
return $this->setIndentation(str_repeat(" ", $iNumber));
}

/**
* @return OutputFormat
*/
public function nextLevel()
{
if ($this->oNextLevelFormat === null) {
Expand All @@ -195,11 +269,17 @@ public function nextLevel()
return $this->oNextLevelFormat;
}

/**
* @return void
*/
public function beLenient()
{
$this->bIgnoreExceptions = true;
}

/**
* @return OutputFormatter
*/
public function getFormatter()
{
if ($this->oFormatter === null) {
Expand All @@ -208,25 +288,28 @@ public function getFormatter()
return $this->oFormatter;
}

/**
* @return int
*/
public function level()
{
return $this->iIndentationLevel;
}

/**
* Create format.
* Creates an instance of this class without any particular formatting settings.
*
* @return OutputFormat Format.
* @return self
*/
public static function create()
{
return new OutputFormat();
}

/**
* Create compact format.
* Creates an instance of this class with a preset for compact formatting.
*
* @return OutputFormat Format.
* @return self
*/
public static function createCompact()
{
Expand All @@ -237,9 +320,9 @@ public static function createCompact()
}

/**
* Create pretty format.
* Creates an instance of this class with a preset for pretty formatting.
*
* @return OutputFormat Format.
* @return self
*/
public static function createPretty()
{
Expand Down