Skip to content

Commit f77e5f8

Browse files
committed
Keep more lines under 120 characters
This brings the code one step forward towards PSR-12 compliance.
1 parent c9138f1 commit f77e5f8

File tree

19 files changed

+258
-78
lines changed

19 files changed

+258
-78
lines changed

lib/Sabberworm/CSS/CSSList/CSSList.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,20 @@ private static function parseListItem(ParserState $oParserState, CSSList $oList)
9292
$oAtRule = self::parseAtRule($oParserState);
9393
if ($oAtRule instanceof Charset) {
9494
if (!$bIsRoot) {
95-
throw new UnexpectedTokenException('@charset may only occur in root document', '', 'custom', $oParserState->currentLine());
95+
throw new UnexpectedTokenException(
96+
'@charset may only occur in root document',
97+
'',
98+
'custom',
99+
$oParserState->currentLine()
100+
);
96101
}
97102
if (count($oList->getContents()) > 0) {
98-
throw new UnexpectedTokenException('@charset must be the first parseable token in a document', '', 'custom', $oParserState->currentLine());
103+
throw new UnexpectedTokenException(
104+
'@charset must be the first parseable token in a document',
105+
'',
106+
'custom',
107+
$oParserState->currentLine()
108+
);
99109
}
100110
$oParserState->setCharset($oAtRule->getCharset()->getString());
101111
}
@@ -160,7 +170,12 @@ private static function parseAtRule(ParserState $oParserState)
160170
throw new UnexpectedTokenException('Wrong namespace prefix', $sPrefix, 'custom', $iIdentifierLineNum);
161171
}
162172
if (!($mUrl instanceof CSSString || $mUrl instanceof URL)) {
163-
throw new UnexpectedTokenException('Wrong namespace url of invalid type', $mUrl, 'custom', $iIdentifierLineNum);
173+
throw new UnexpectedTokenException(
174+
'Wrong namespace url of invalid type',
175+
$mUrl,
176+
'custom',
177+
$iIdentifierLineNum
178+
);
164179
}
165180
return new CSSNamespace($mUrl, $sPrefix, $iIdentifierLineNum);
166181
} else {
@@ -194,8 +209,9 @@ private static function parseAtRule(ParserState $oParserState)
194209
}
195210
}
196211

197-
/**
198-
* Tests an identifier for a given value. Since identifiers are all keywords, they can be vendor-prefixed. We need to check for these versions too.
212+
/**
213+
* Tests an identifier for a given value. Since identifiers are all keywords, they can be vendor-prefixed.
214+
* We need to check for these versions too.
199215
*/
200216
private static function identifierIs($sIdentifier, $sMatch)
201217
{
@@ -246,7 +262,11 @@ public function splice($iOffset, $iLength = null, $mReplacement = null)
246262

247263
/**
248264
* Removes an item from the CSS list.
249-
* @param RuleSet|Import|Charset|CSSList $oItemToRemove May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery)
265+
*
266+
* @param RuleSet|Import|Charset|CSSList $oItemToRemove
267+
* May be a RuleSet (most likely a DeclarationBlock), a Import,
268+
* a Charset or another CSSList (most likely a MediaQuery)
269+
*
250270
* @return bool Whether the item was removed.
251271
*/
252272
public function remove($oItemToRemove)
@@ -262,7 +282,9 @@ public function remove($oItemToRemove)
262282
/**
263283
* Replaces an item from the CSS list.
264284
*
265-
* @param RuleSet|Import|Charset|CSSList $oItemToRemove May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery)
285+
* @param RuleSet|Import|Charset|CSSList $oItemToRemove
286+
* May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset
287+
* or another CSSList (most likely a MediaQuery)
266288
*/
267289
public function replace($oOldItem, $mNewItem)
268290
{
@@ -306,7 +328,11 @@ public function removeDeclarationBlockBySelector($mSelector, $bRemoveAll = false
306328
foreach ($mSelector as $iKey => &$mSel) {
307329
if (!($mSel instanceof Selector)) {
308330
if (!Selector::isValid($mSel)) {
309-
throw new UnexpectedTokenException("Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.", $mSel, "custom");
331+
throw new UnexpectedTokenException(
332+
"Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.",
333+
$mSel,
334+
"custom"
335+
);
310336
}
311337
$mSel = new Selector($mSel);
312338
}

lib/Sabberworm/CSS/CSSList/Document.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use Sabberworm\CSS\Parsing\ParserState;
66

77
/**
8-
* The root CSSList of a parsed file. Contains all top-level css contents, mostly declaration blocks, but also any @-rules encountered.
8+
* The root CSSList of a parsed file. Contains all top-level css contents, mostly declaration blocks,
9+
* but also any @-rules encountered.
910
*/
1011
class Document extends CSSBlockList
1112
{
@@ -62,7 +63,9 @@ public function getAllRuleSets()
6263

6364
/**
6465
* Returns all Value objects found recursively in the tree.
65-
* @param (object|string) $mElement the CSSList or RuleSet to start the search from (defaults to the whole document). If a string is given, it is used as rule name filter (@see{RuleSet->getRules()}).
66+
* @param (object|string) $mElement
67+
* the CSSList or RuleSet to start the search from (defaults to the whole document).
68+
* If a string is given, it is used as rule name filter (@see{RuleSet->getRules()}).
6669
* @param (bool) $bSearchInFunctionArguments whether to also return Value objects used as Function arguments.
6770
*/
6871
public function getAllValues($mElement = null, $bSearchInFunctionArguments = false)
@@ -81,8 +84,12 @@ public function getAllValues($mElement = null, $bSearchInFunctionArguments = fal
8184

8285
/**
8386
* Returns all Selector objects found recursively in the tree.
84-
* Note that this does not yield the full DeclarationBlock that the selector belongs to (and, currently, there is no way to get to that).
85-
* @param $sSpecificitySearch An optional filter by specificity. May contain a comparison operator and a number or just a number (defaults to "==").
87+
* Note that this does not yield the full DeclarationBlock that the selector belongs to
88+
* (and, currently, there is no way to get to that).
89+
*
90+
* @param string $sSpecificitySearch
91+
* An optional filter by specificity.
92+
* May contain a comparison operator and a number or just a number (defaults to "==").
8693
* @example getSelectorsBySpecificity('>= 100')
8794
*/
8895
public function getSelectorsBySpecificity($sSpecificitySearch = null)

lib/Sabberworm/CSS/OutputFormat.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ public static function create()
186186
public static function createCompact()
187187
{
188188
$format = self::create();
189-
$format->set('Space*Rules', "")->set('Space*Blocks', "")->setSpaceAfterRuleName('')->setSpaceBeforeOpeningBrace('')->setSpaceAfterSelectorSeparator('');
189+
$format->set('Space*Rules', "")->set('Space*Blocks', "")->setSpaceAfterRuleName('')
190+
->setSpaceBeforeOpeningBrace('')->setSpaceAfterSelectorSeparator('');
190191
return $format;
191192
}
192193

@@ -198,7 +199,8 @@ public static function createCompact()
198199
public static function createPretty()
199200
{
200201
$format = self::create();
201-
$format->set('Space*Rules', "\n")->set('Space*Blocks', "\n")->setSpaceBetweenBlocks("\n\n")->set('SpaceAfterListArgumentSeparator', ['default' => '', ',' => ' ']);
202+
$format->set('Space*Rules', "\n")->set('Space*Blocks', "\n")
203+
->setSpaceBetweenBlocks("\n\n")->set('SpaceAfterListArgumentSeparator', ['default' => '', ',' => ' ']);
202204
return $format;
203205
}
204206
}
@@ -215,7 +217,8 @@ public function __construct(OutputFormat $oFormat)
215217
public function space($sName, $sType = null)
216218
{
217219
$sSpaceString = $this->oFormat->get("Space$sName");
218-
// If $sSpaceString is an array, we have multple values configured depending on the type of object the space applies to
220+
// If $sSpaceString is an array, we have multple values configured
221+
// depending on the type of object the space applies to
219222
if (is_array($sSpaceString)) {
220223
if ($sType !== null && isset($sSpaceString[$sType])) {
221224
$sSpaceString = $sSpaceString[$sType];

lib/Sabberworm/CSS/Parsing/ParserState.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public function parseIdentifier($bIgnoreCase = true)
8383
public function parseCharacter($bIsForIdentifier)
8484
{
8585
if ($this->peek() === '\\') {
86-
if ($bIsForIdentifier && $this->oParserSettings->bLenientParsing && ($this->comes('\0') || $this->comes('\9'))) {
86+
if (
87+
$bIsForIdentifier && $this->oParserSettings->bLenientParsing
88+
&& ($this->comes('\0') || $this->comes('\9'))
89+
) {
8790
// Non-strings can contain \0 or \9 which is an IE hack supported in lenient parsing.
8891
return null;
8992
}
@@ -265,7 +268,12 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
265268
}
266269

267270
$this->iCurrentPosition = $start;
268-
throw new UnexpectedEOFException('One of ("' . implode('","', $aEnd) . '")', $this->peek(5), 'search', $this->iLineNo);
271+
throw new UnexpectedEOFException(
272+
'One of ("' . implode('","', $aEnd) . '")',
273+
$this->peek(5),
274+
'search',
275+
$this->iLineNo
276+
);
269277
}
270278

271279
private function inputLeft()

lib/Sabberworm/CSS/Property/AtRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
interface AtRule extends Renderable, Commentable
99
{
10-
// Since there are more set rules than block rules, we’re whitelisting the block rules and have anything else be treated as a set rule.
10+
// Since there are more set rules than block rules,
11+
// we’re whitelisting the block rules and have anything else be treated as a set rule.
1112
const BLOCK_RULES = 'media/document/supports/region-style/font-feature-values';
1213
// …and more font-specific ones (to be used inside font-feature-values)
1314
const SET_RULES = 'font-face/counter-style/page/swash/styleset/annotation';

lib/Sabberworm/CSS/Property/Import.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public function __toString()
7272
*/
7373
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
7474
{
75-
return "@import " . $this->oLocation->render($oOutputFormat) . ($this->sMediaQuery === null ? '' : ' ' . $this->sMediaQuery) . ';';
75+
return "@import " . $this->oLocation->render($oOutputFormat)
76+
. ($this->sMediaQuery === null ? '' : ' ' . $this->sMediaQuery) . ';';
7677
}
7778

7879
/**

lib/Sabberworm/CSS/Rule/Rule.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ public function __construct($sRule, $iLineNo = 0, $iColNo = 0)
3737
public static function parse(ParserState $oParserState)
3838
{
3939
$aComments = $oParserState->consumeWhiteSpace();
40-
$oRule = new Rule($oParserState->parseIdentifier(!$oParserState->comes("--")), $oParserState->currentLine(), $oParserState->currentColumn());
40+
$oRule = new Rule(
41+
$oParserState->parseIdentifier(!$oParserState->comes("--")),
42+
$oParserState->currentLine(),
43+
$oParserState->currentColumn()
44+
);
4145
$oRule->setComments($aComments);
4246
$oRule->addComments($oParserState->consumeWhiteSpace());
4347
$oParserState->consume(':');
@@ -117,7 +121,8 @@ public function setValue($mValue)
117121
}
118122

119123
/**
120-
* @deprecated Old-Style 2-dimensional array given. Retained for (some) backwards-compatibility. Use setValue() instead and wrapp the value inside a RuleValueList if necessary.
124+
* @deprecated Old-Style 2-dimensional array given. Retained for (some) backwards-compatibility.
125+
* Use setValue() instead and wrap the value inside a RuleValueList if necessary.
121126
*/
122127
public function setValues($aSpaceSeparatedValues)
123128
{
@@ -153,7 +158,8 @@ public function setValues($aSpaceSeparatedValues)
153158
}
154159

155160
/**
156-
* @deprecated Old-Style 2-dimensional array returned. Retained for (some) backwards-compatibility. Use getValue() instead and check for the existance of a (nested set of) ValueList object(s).
161+
* @deprecated Old-Style 2-dimensional array returned. Retained for (some) backwards-compatibility.
162+
* Use getValue() instead and check for the existance of a (nested set of) ValueList object(s).
157163
*/
158164
public function getValues()
159165
{
@@ -180,7 +186,8 @@ public function getValues()
180186
}
181187

182188
/**
183-
* Adds a value to the existing value. Value will be appended if a RuleValueList exists of the given type. Otherwise, the existing value will be wrapped by one.
189+
* Adds a value to the existing value. Value will be appended if a RuleValueList exists of the given type.
190+
* Otherwise, the existing value will be wrapped by one.
184191
*/
185192
public function addValue($mValue, $sType = ' ')
186193
{

lib/Sabberworm/CSS/RuleSet/DeclarationBlock.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public static function parse(ParserState $oParserState, $oList = null)
4040
$aSelectorParts = [];
4141
$sStringWrapperChar = false;
4242
do {
43-
$aSelectorParts[] = $oParserState->consume(1) . $oParserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments);
43+
$aSelectorParts[] = $oParserState->consume(1)
44+
. $oParserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments);
4445
if (in_array($oParserState->peek(), ['\'', '"']) && substr(end($aSelectorParts), -1) != "\\") {
4546
if ($sStringWrapperChar === false) {
4647
$sStringWrapperChar = $oParserState->peek();
@@ -80,12 +81,20 @@ public function setSelectors($mSelector, $oList = null)
8081
if (!($mSelector instanceof Selector)) {
8182
if ($oList === null || !($oList instanceof KeyFrame)) {
8283
if (!Selector::isValid($mSelector)) {
83-
throw new UnexpectedTokenException("Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.", $mSelector, "custom");
84+
throw new UnexpectedTokenException(
85+
"Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.",
86+
$mSelector,
87+
"custom"
88+
);
8489
}
8590
$this->aSelectors[$iKey] = new Selector($mSelector);
8691
} else {
8792
if (!KeyframeSelector::isValid($mSelector)) {
88-
throw new UnexpectedTokenException("Selector did not match '" . KeyframeSelector::SELECTOR_VALIDATION_RX . "'.", $mSelector, "custom");
93+
throw new UnexpectedTokenException(
94+
"Selector did not match '" . KeyframeSelector::SELECTOR_VALIDATION_RX . "'.",
95+
$mSelector,
96+
"custom"
97+
);
8998
}
9099
$this->aSelectors[$iKey] = new KeyframeSelector($mSelector);
91100
}
@@ -353,7 +362,9 @@ public function expandBackgroundShorthand()
353362
$aBgProperties = [
354363
'background-color' => ['transparent'], 'background-image' => ['none'],
355364
'background-repeat' => ['repeat'], 'background-attachment' => ['scroll'],
356-
'background-position' => [new Size(0, '%', null, false, $this->iLineNo), new Size(0, '%', null, false, $this->iLineNo)]
365+
'background-position' => [
366+
new Size(0, '%', null, false, $this->iLineNo), new Size(0, '%', null, false, $this->iLineNo)
367+
]
357368
];
358369
$mRuleValue = $oRule->getValue();
359370
$aValues = [];
@@ -696,7 +707,10 @@ public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
696707
throw new OutputException("Attempt to print declaration block with missing selector", $this->iLineNo);
697708
}
698709
$sResult = $oOutputFormat->sBeforeDeclarationBlock;
699-
$sResult .= $oOutputFormat->implode($oOutputFormat->spaceBeforeSelectorSeparator() . ',' . $oOutputFormat->spaceAfterSelectorSeparator(), $this->aSelectors);
710+
$sResult .= $oOutputFormat->implode(
711+
$oOutputFormat->spaceBeforeSelectorSeparator() . ',' . $oOutputFormat->spaceAfterSelectorSeparator(),
712+
$this->aSelectors
713+
);
700714
$sResult .= $oOutputFormat->sAfterDeclarationBlockSelectors;
701715
$sResult .= $oOutputFormat->spaceBeforeOpeningBrace() . '{';
702716
$sResult .= parent::render($oOutputFormat);

0 commit comments

Comments
 (0)