Skip to content
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
10 changes: 5 additions & 5 deletions src/CSSList/CSSList.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public static function parseList(ParserState $parserState, CSSList $oList): void
$parserState = new ParserState($parserState, Settings::create());
}
$bLenientParsing = $parserState->getSettings()->bLenientParsing;
$aComments = [];
$comments = [];
while (!$parserState->isEnd()) {
$aComments = \array_merge($aComments, $parserState->consumeWhiteSpace());
$comments = \array_merge($comments, $parserState->consumeWhiteSpace());
$oListItem = null;
if ($bLenientParsing) {
try {
Expand All @@ -87,12 +87,12 @@ public static function parseList(ParserState $parserState, CSSList $oList): void
return;
}
if ($oListItem) {
$oListItem->addComments($aComments);
$oListItem->addComments($comments);
$oList->append($oListItem);
}
$aComments = $parserState->consumeWhiteSpace();
$comments = $parserState->consumeWhiteSpace();
}
$oList->addComments($aComments);
$oList->addComments($comments);
if (!$bIsRoot && !$bLenientParsing) {
throw new SourceException('Unexpected end of document', $parserState->currentLine());
}
Expand Down
11 changes: 3 additions & 8 deletions src/OutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,17 @@ public function removeLastSemicolon($sString)
return \implode(';', $sString);
}

/**
* @param array<Commentable> $aComments
*
* @return string
*/
public function comments(Commentable $oCommentable): string
{
if (!$this->oFormat->bRenderComments) {
return '';
}

$sResult = '';
$aComments = $oCommentable->getComments();
$iLastCommentIndex = \count($aComments) - 1;
$comments = $oCommentable->getComments();
$iLastCommentIndex = \count($comments) - 1;

foreach ($aComments as $i => $oComment) {
foreach ($comments as $i => $oComment) {
$sResult .= $oComment->render($this->oFormat);
$sResult .= $i === $iLastCommentIndex ? $this->spaceAfterBlocks() : $this->spaceBetweenBlocks();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Parsing/ParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function parseCharacter($bIsForIdentifier)
*/
public function consumeWhiteSpace(): array
{
$aComments = [];
$comments = [];
do {
while (\preg_match('/\\s/isSu', $this->peek()) === 1) {
$this->consume(1);
Expand All @@ -241,16 +241,16 @@ public function consumeWhiteSpace(): array
$oComment = $this->consumeComment();
} catch (UnexpectedEOFException $e) {
$this->iCurrentPosition = $this->iLength;
return $aComments;
return $comments;
}
} else {
$oComment = $this->consumeComment();
}
if ($oComment !== false) {
$aComments[] = $oComment;
$comments[] = $oComment;
}
} while ($oComment !== false);
return $aComments;
return $comments;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public function __construct($sRule, $lineNumber = 0, $iColNo = 0)
*/
public static function parse(ParserState $parserState): Rule
{
$aComments = $parserState->consumeWhiteSpace();
$comments = $parserState->consumeWhiteSpace();
$rule = new Rule(
$parserState->parseIdentifier(!$parserState->comes('--')),
$parserState->currentLine(),
$parserState->currentColumn()
);
$rule->setComments($aComments);
$rule->setComments($comments);
$rule->addComments($parserState->consumeWhiteSpace());
$parserState->consume(':');
$oValue = Value::parseValue($parserState, self::listDelimiterForRule($rule->getRule()));
Expand Down
6 changes: 3 additions & 3 deletions src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public function __construct($lineNumber = 0)
*/
public static function parse(ParserState $parserState, $oList = null)
{
$aComments = [];
$comments = [];
$oResult = new DeclarationBlock($parserState->currentLine());
try {
$aSelectorParts = [];
$sStringWrapperChar = false;
do {
$aSelectorParts[] = $parserState->consume(1)
. $parserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments);
. $parserState->consumeUntil(['{', '}', '\'', '"'], false, false, $comments);
if (\in_array($parserState->peek(), ['\'', '"'], true) && \substr(\end($aSelectorParts), -1) != '\\') {
if ($sStringWrapperChar === false) {
$sStringWrapperChar = $parserState->peek();
Expand All @@ -78,7 +78,7 @@ public static function parse(ParserState $parserState, $oList = null)
throw $e;
}
}
$oResult->setComments($aComments);
$oResult->setComments($comments);
RuleSet::parseRuleSet($parserState, $oResult);
return $oResult;
}
Expand Down