Skip to content

Commit 9c39fd2

Browse files
authored
Merge pull request #226 from oliverklee/cleanup/line-lengths
Keep more lines under 120 characters
2 parents f69d77f + f77e5f8 commit 9c39fd2

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
@@ -91,10 +91,20 @@ private static function parseListItem(ParserState $oParserState, CSSList $oList)
9191
$oAtRule = self::parseAtRule($oParserState);
9292
if ($oAtRule instanceof Charset) {
9393
if (!$bIsRoot) {
94-
throw new UnexpectedTokenException('@charset may only occur in root document', '', 'custom', $oParserState->currentLine());
94+
throw new UnexpectedTokenException(
95+
'@charset may only occur in root document',
96+
'',
97+
'custom',
98+
$oParserState->currentLine()
99+
);
95100
}
96101
if (count($oList->getContents()) > 0) {
97-
throw new UnexpectedTokenException('@charset must be the first parseable token in a document', '', 'custom', $oParserState->currentLine());
102+
throw new UnexpectedTokenException(
103+
'@charset must be the first parseable token in a document',
104+
'',
105+
'custom',
106+
$oParserState->currentLine()
107+
);
98108
}
99109
$oParserState->setCharset($oAtRule->getCharset()->getString());
100110
}
@@ -159,7 +169,12 @@ private static function parseAtRule(ParserState $oParserState)
159169
throw new UnexpectedTokenException('Wrong namespace prefix', $sPrefix, 'custom', $iIdentifierLineNum);
160170
}
161171
if (!($mUrl instanceof CSSString || $mUrl instanceof URL)) {
162-
throw new UnexpectedTokenException('Wrong namespace url of invalid type', $mUrl, 'custom', $iIdentifierLineNum);
172+
throw new UnexpectedTokenException(
173+
'Wrong namespace url of invalid type',
174+
$mUrl,
175+
'custom',
176+
$iIdentifierLineNum
177+
);
163178
}
164179
return new CSSNamespace($mUrl, $sPrefix, $iIdentifierLineNum);
165180
} else {
@@ -193,8 +208,9 @@ private static function parseAtRule(ParserState $oParserState)
193208
}
194209
}
195210

196-
/**
197-
* 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.
211+
/**
212+
* Tests an identifier for a given value. Since identifiers are all keywords, they can be vendor-prefixed.
213+
* We need to check for these versions too.
198214
*/
199215
private static function identifierIs($sIdentifier, $sMatch)
200216
{
@@ -245,7 +261,11 @@ public function splice($iOffset, $iLength = null, $mReplacement = null)
245261

246262
/**
247263
* Removes an item from the CSS list.
248-
* @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)
264+
*
265+
* @param RuleSet|Import|Charset|CSSList $oItemToRemove
266+
* May be a RuleSet (most likely a DeclarationBlock), a Import,
267+
* a Charset or another CSSList (most likely a MediaQuery)
268+
*
249269
* @return bool Whether the item was removed.
250270
*/
251271
public function remove($oItemToRemove)
@@ -261,7 +281,9 @@ public function remove($oItemToRemove)
261281
/**
262282
* Replaces an item from the CSS list.
263283
*
264-
* @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)
284+
* @param RuleSet|Import|Charset|CSSList $oItemToRemove
285+
* May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset
286+
* or another CSSList (most likely a MediaQuery)
265287
*/
266288
public function replace($oOldItem, $mNewItem)
267289
{
@@ -305,7 +327,11 @@ public function removeDeclarationBlockBySelector($mSelector, $bRemoveAll = false
305327
foreach ($mSelector as $iKey => &$mSel) {
306328
if (!($mSel instanceof Selector)) {
307329
if (!Selector::isValid($mSel)) {
308-
throw new UnexpectedTokenException("Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.", $mSel, "custom");
330+
throw new UnexpectedTokenException(
331+
"Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.",
332+
$mSel,
333+
"custom"
334+
);
309335
}
310336
$mSel = new Selector($mSel);
311337
}

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
@@ -185,7 +185,8 @@ public static function create()
185185
public static function createCompact()
186186
{
187187
$format = self::create();
188-
$format->set('Space*Rules', "")->set('Space*Blocks', "")->setSpaceAfterRuleName('')->setSpaceBeforeOpeningBrace('')->setSpaceAfterSelectorSeparator('');
188+
$format->set('Space*Rules', "")->set('Space*Blocks', "")->setSpaceAfterRuleName('')
189+
->setSpaceBeforeOpeningBrace('')->setSpaceAfterSelectorSeparator('');
189190
return $format;
190191
}
191192

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

lib/Sabberworm/CSS/Parsing/ParserState.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public function parseIdentifier($bIgnoreCase = true)
8181
public function parseCharacter($bIsForIdentifier)
8282
{
8383
if ($this->peek() === '\\') {
84-
if ($bIsForIdentifier && $this->oParserSettings->bLenientParsing && ($this->comes('\0') || $this->comes('\9'))) {
84+
if (
85+
$bIsForIdentifier && $this->oParserSettings->bLenientParsing
86+
&& ($this->comes('\0') || $this->comes('\9'))
87+
) {
8588
// Non-strings can contain \0 or \9 which is an IE hack supported in lenient parsing.
8689
return null;
8790
}
@@ -263,7 +266,12 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
263266
}
264267

265268
$this->iCurrentPosition = $start;
266-
throw new UnexpectedEOFException('One of ("' . implode('","', $aEnd) . '")', $this->peek(5), 'search', $this->iLineNo);
269+
throw new UnexpectedEOFException(
270+
'One of ("' . implode('","', $aEnd) . '")',
271+
$this->peek(5),
272+
'search',
273+
$this->iLineNo
274+
);
267275
}
268276

269277
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)