Skip to content

Commit dca1159

Browse files
committed
Autoformat all PHP files with PhpStorm
This allows contributors to autoformat their changed files without risking to also affect the unchanged code. This change also fixes a bunch of PSR-12 violations, and it hopefully also makes the code a bit nicer to read.
1 parent 286fe5f commit dca1159

27 files changed

+419
-183
lines changed

src/CSSList/AtRuleBlockList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
6161
if ($sArgs) {
6262
$sArgs = ' ' . $sArgs;
6363
}
64-
$sResult = $oOutputFormat->sBeforeAtRuleBlock;
64+
$sResult = $oOutputFormat->sBeforeAtRuleBlock;
6565
$sResult .= "@{$this->sType}$sArgs{$oOutputFormat->spaceBeforeOpeningBrace()}{";
6666
$sResult .= parent::render($oOutputFormat);
6767
$sResult .= '}';

src/CSSList/CSSList.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ private static function identifierIs($sIdentifier, $sMatch)
219219
?: preg_match("/^(-\\w+-)?$sMatch$/i", $sIdentifier) === 1;
220220
}
221221

222-
223222
/**
224223
* @return int
225224
*/
@@ -251,8 +250,8 @@ public function append($oItem)
251250
/**
252251
* Splice the list of contents.
253252
*
254-
* @param int $iOffset Offset.
255-
* @param int $iLength Length. Optional.
253+
* @param int $iOffset Offset.
254+
* @param int $iLength Length. Optional.
256255
* @param RuleSet[] $mReplacement Replacement. Optional.
257256
*/
258257
public function splice($iOffset, $iLength = null, $mReplacement = null)
@@ -302,6 +301,7 @@ public function replace($oOldItem, $mNewItem)
302301

303302
/**
304303
* Set the contents.
304+
*
305305
* @param array<int, RuleSet|Import|Charset|CSSList> $aContents Objects to set as content.
306306
*/
307307
public function setContents(array $aContents)
@@ -314,6 +314,7 @@ public function setContents(array $aContents)
314314

315315
/**
316316
* Removes a declaration block from the CSS list if it matches all given selectors.
317+
*
317318
* @param array|string $mSelector The selectors to match.
318319
* @param boolean $bRemoveAll Whether to stop at the first declaration block found or remove all blocks
319320
*/
@@ -391,8 +392,8 @@ public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
391392
}
392393

393394
/**
394-
* Return true if the list can not be further outdented. Only important when rendering.
395-
*/
395+
* Return true if the list can not be further outdented. Only important when rendering.
396+
*/
396397
abstract public function isRootList();
397398

398399
/**

src/CSSList/Document.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Document extends CSSBlockList
1212
{
1313
/**
1414
* Document constructor.
15+
*
1516
* @param int $iLineNo
1617
*/
1718
public function __construct($iLineNo = 0)
@@ -63,10 +64,13 @@ public function getAllRuleSets()
6364

6465
/**
6566
* Returns all Value objects found recursively in the tree.
67+
*
6668
* @param object|string $mElement
6769
* 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()).
70+
* If a string is given, it is used as rule name filter.
6971
* @param bool $bSearchInFunctionArguments whether to also return Value objects used as Function arguments.
72+
*
73+
* @see RuleSet->getRules()
7074
*/
7175
public function getAllValues($mElement = null, $bSearchInFunctionArguments = false)
7276
{
@@ -90,6 +94,7 @@ public function getAllValues($mElement = null, $bSearchInFunctionArguments = fal
9094
* @param string $sSpecificitySearch
9195
* An optional filter by specificity.
9296
* May contain a comparison operator and a number or just a number (defaults to "==").
97+
*
9398
* @example getSelectorsBySpecificity('>= 100')
9499
*/
95100
public function getSelectorsBySpecificity($sSpecificitySearch = null)
@@ -119,7 +124,6 @@ public function createShorthands()
119124
}
120125
}
121126

122-
123127
/**
124128
* Override render() to make format argument optional
125129
*

src/CSSList/KeyFrame.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct($iLineNo = 0)
2020
{
2121
parent::__construct($iLineNo);
2222
$this->vendorKeyFrame = null;
23-
$this->animationName = null;
23+
$this->animationName = null;
2424
}
2525

2626
public function setVendorKeyFrame($vendorKeyFrame)

src/Comment/Comment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class Comment implements Renderable
88
{
99
protected $iLineNo;
10+
1011
protected $sComment;
1112

1213
public function __construct($sComment = '', $iLineNo = 0)

src/OutputFormat.php

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,85 @@
55
/**
66
* Class OutputFormat
77
*
8-
* @method OutputFormat setSemicolonAfterLastRule( bool $bSemicolonAfterLastRule ) Set whether semicolons are added after last rule.
8+
* @method OutputFormat setSemicolonAfterLastRule(bool $bSemicolonAfterLastRule) Set whether semicolons are added after
9+
* last rule.
910
*/
1011
class OutputFormat
1112
{
1213
/**
13-
* Value format
14-
*/
14+
* Value format
15+
*/
1516
// " means double-quote, ' means single-quote
1617
public $sStringQuotingType = '"';
18+
1719
// Output RGB colors in hash notation if possible
1820
public $bRGBHashNotation = true;
1921

2022
/**
21-
* Declaration format
22-
*/
23+
* Declaration format
24+
*/
2325
// Semicolon after the last rule of a declaration block can be omitted. To do that, set this false.
2426
public $bSemicolonAfterLastRule = true;
2527

2628
/**
27-
* Spacing
28-
* Note that these strings are not sanity-checked: the value should only consist of whitespace
29-
* Any newline character will be indented according to the current level.
30-
* The triples (After, Before, Between) can be set using a wildcard (e.g. `$oFormat->set('Space*Rules', "\n");`)
31-
*/
29+
* Spacing
30+
* Note that these strings are not sanity-checked: the value should only consist of whitespace
31+
* Any newline character will be indented according to the current level.
32+
* The triples (After, Before, Between) can be set using a wildcard (e.g. `$oFormat->set('Space*Rules', "\n");`)
33+
*/
3234
public $sSpaceAfterRuleName = ' ';
3335

3436
public $sSpaceBeforeRules = '';
37+
3538
public $sSpaceAfterRules = '';
39+
3640
public $sSpaceBetweenRules = '';
3741

3842
public $sSpaceBeforeBlocks = '';
43+
3944
public $sSpaceAfterBlocks = '';
45+
4046
public $sSpaceBetweenBlocks = "\n";
4147

4248
// Content injected in and around @-rule blocks.
4349
public $sBeforeAtRuleBlock = '';
50+
4451
public $sAfterAtRuleBlock = '';
4552

4653
// This is what’s printed before and after the comma if a declaration block contains multiple selectors.
4754
public $sSpaceBeforeSelectorSeparator = '';
55+
4856
public $sSpaceAfterSelectorSeparator = ' ';
57+
4958
// This is what’s printed after the comma of value lists
5059
public $sSpaceBeforeListArgumentSeparator = '';
60+
5161
public $sSpaceAfterListArgumentSeparator = '';
5262

5363
public $sSpaceBeforeOpeningBrace = ' ';
5464

5565
// Content injected in and around declaration blocks.
5666
public $sBeforeDeclarationBlock = '';
67+
5768
public $sAfterDeclarationBlockSelectors = '';
69+
5870
public $sAfterDeclarationBlock = '';
5971

6072
/**
61-
* Indentation
62-
*/
73+
* Indentation
74+
*/
6375
// Indentation character(s) per level. Only applicable if newlines are used in any of the spacing settings.
6476
public $sIndentation = "\t";
6577

6678
/**
67-
* Output exceptions.
68-
*/
79+
* Output exceptions.
80+
*/
6981
public $bIgnoreExceptions = false;
7082

71-
7283
private $oFormatter = null;
84+
7385
private $oNextLevelFormat = null;
86+
7487
private $iIndentationLevel = 0;
7588

7689
public function __construct()
@@ -93,7 +106,12 @@ public function set($aNames, $mValue)
93106
{
94107
$aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i'];
95108
if (is_string($aNames) && strpos($aNames, '*') !== false) {
96-
$aNames = [str_replace('*', 'Before', $aNames), str_replace('*', 'Between', $aNames), str_replace('*', 'After', $aNames)];
109+
$aNames =
110+
[
111+
str_replace('*', 'Before', $aNames),
112+
str_replace('*', 'Between', $aNames),
113+
str_replace('*', 'After', $aNames),
114+
];
97115
} elseif (!is_array($aNames)) {
98116
$aNames = [$aNames];
99117
}

src/Parsing/OutputException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace Sabberworm\CSS\Parsing;
44

55
/**
6-
* Thrown if the CSS parsers attempts to print something invalid
7-
*/
6+
* Thrown if the CSS parsers attempts to print something invalid
7+
*/
88
class OutputException extends SourceException
99
{
1010
public function __construct($sMessage, $iLineNo = 0)

src/Parsing/ParserState.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ class ParserState
1414
private $sText;
1515

1616
private $aText;
17+
1718
private $iCurrentPosition;
19+
1820
private $sCharset;
21+
1922
private $iLength;
23+
2024
private $iLineNo;
2125

2226
public function __construct($sText, Settings $oParserSettings, $iLineNo = 1)
@@ -117,12 +121,12 @@ public function parseCharacter($bIsForIdentifier)
117121
$peek = ord($this->peek());
118122
// Ranges: a-z A-Z 0-9 - _
119123
if (
120-
($peek >= 97 && $peek <= 122) ||
121-
($peek >= 65 && $peek <= 90) ||
122-
($peek >= 48 && $peek <= 57) ||
123-
($peek === 45) ||
124-
($peek === 95) ||
125-
($peek > 0xa1)
124+
($peek >= 97 && $peek <= 122)
125+
|| ($peek >= 65 && $peek <= 90)
126+
|| ($peek >= 48 && $peek <= 57)
127+
|| ($peek === 45)
128+
|| ($peek === 95)
129+
|| ($peek > 0xa1)
126130
) {
127131
return $this->consume(1);
128132
}

src/Parsing/SourceException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class SourceException extends \Exception
66
{
77
private $iLineNo;
8+
89
public function __construct($sMessage, $iLineNo = 0)
910
{
1011
$this->iLineNo = $iLineNo;

src/Parsing/UnexpectedEOFException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Sabberworm\CSS\Parsing;
44

55
/**
6-
* Thrown if the CSS parsers encounters end of file it did not expect
7-
* Extends UnexpectedTokenException in order to preserve backwards compatibility
8-
*/
6+
* Thrown if the CSS parsers encounters end of file it did not expect
7+
* Extends UnexpectedTokenException in order to preserve backwards compatibility
8+
*/
99
class UnexpectedEOFException extends UnexpectedTokenException
1010
{
1111
}

src/Parsing/UnexpectedTokenException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
namespace Sabberworm\CSS\Parsing;
44

55
/**
6-
* Thrown if the CSS parsers encounters a token it did not expect
7-
*/
6+
* Thrown if the CSS parsers encounters a token it did not expect
7+
*/
88
class UnexpectedTokenException extends SourceException
99
{
1010
private $sExpected;
11+
1112
private $sFound;
13+
1214
// Possible values: literal, identifier, count, expression, search
1315
private $sMatchType;
1416

src/Property/CSSNamespace.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
namespace Sabberworm\CSS\Property;
44

55
/**
6-
* CSSNamespace represents an @namespace rule.
7-
*/
6+
* CSSNamespace represents an @namespace rule.
7+
*/
88
class CSSNamespace implements AtRule
99
{
1010
private $mUrl;
11+
1112
private $sPrefix;
13+
1214
private $iLineNo;
15+
1316
protected $aComments;
1417

1518
public function __construct($mUrl, $sPrefix = null, $iLineNo = 0)
@@ -40,7 +43,8 @@ public function __toString()
4043
*/
4144
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
4245
{
43-
return '@namespace ' . ($this->sPrefix === null ? '' : $this->sPrefix . ' ') . $this->mUrl->render($oOutputFormat) . ';';
46+
return '@namespace ' . ($this->sPrefix === null ? '' : $this->sPrefix . ' ')
47+
. $this->mUrl->render($oOutputFormat) . ';';
4448
}
4549

4650
public function getUrl()

src/Property/Import.php

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

77
/**
8-
* Class representing an @import rule.
9-
*/
8+
* Class representing an @import rule.
9+
*/
1010
class Import implements AtRule
1111
{
1212
/**
@@ -52,12 +52,12 @@ public function getLineNo()
5252

5353
public function setLocation($oLocation)
5454
{
55-
$this->oLocation = $oLocation;
55+
$this->oLocation = $oLocation;
5656
}
5757

5858
public function getLocation()
5959
{
60-
return $this->oLocation;
60+
return $this->oLocation;
6161
}
6262

6363
public function __toString()

src/Property/Selector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Sabberworm\CSS\Property;
44

55
/**
6-
* Class representing a single CSS selector. Selectors have to be split by the comma prior to being passed into this class.
6+
* Class representing a single CSS selector. Selectors have to be split by the comma prior to being passed into this
7+
* class.
78
*/
89
class Selector
910
{
@@ -47,6 +48,7 @@ class Selector
4748
/ux';
4849

4950
private $sSelector;
51+
5052
private $iSpecificity;
5153

5254
public static function isValid($sSelector)

0 commit comments

Comments
 (0)