Skip to content

Commit 43e100d

Browse files
committed
[TASK] Clean up the code with Rector
Just the Rector changes, and some reundancy removal related to those, but nothing more.
1 parent b56f7c6 commit 43e100d

File tree

10 files changed

+25
-38
lines changed

10 files changed

+25
-38
lines changed

src/CSSList/CSSList.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ private static function parseAtRule(ParserState $oParserState)
169169
$sMediaQuery = \trim($oParserState->consumeUntil([';', ParserState::EOF]));
170170
}
171171
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
172-
return new Import($oLocation, $sMediaQuery ?: null, $iIdentifierLineNum);
172+
return new Import(
173+
$oLocation,
174+
$sMediaQuery !== null && $sMediaQuery !== '' && $sMediaQuery !== '0' ? $sMediaQuery : null,
175+
$iIdentifierLineNum
176+
);
173177
} elseif ($sIdentifier === 'charset') {
174178
$oCharsetString = CSSString::parse($oParserState);
175179
$oParserState->consumeWhiteSpace();
@@ -238,11 +242,8 @@ private static function parseAtRule(ParserState $oParserState)
238242
/**
239243
* Tests an identifier for a given value. Since identifiers are all keywords, they can be vendor-prefixed.
240244
* We need to check for these versions too.
241-
*
242-
* @param string $sIdentifier
243-
* @param string $sMatch
244245
*/
245-
private static function identifierIs($sIdentifier, $sMatch): bool
246+
private static function identifierIs($sIdentifier, string $sMatch): bool
246247
{
247248
return (\strcasecmp($sIdentifier, $sMatch) === 0)
248249
?: \preg_match("/^(-\\w+-)?$sMatch$/i", $sIdentifier) === 1;

src/OutputFormat.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function set($aNames, $mValue)
230230
*
231231
* @throws \Exception
232232
*/
233-
public function __call($sMethodName, array $aArguments)
233+
public function __call(string $sMethodName, array $aArguments)
234234
{
235235
if (\strpos($sMethodName, 'set') === 0) {
236236
return $this->set(\substr($sMethodName, 3), $aArguments[0]);
@@ -310,10 +310,8 @@ public static function create(): OutputFormat
310310

311311
/**
312312
* Creates an instance of this class with a preset for compact formatting.
313-
*
314-
* @return self
315313
*/
316-
public static function createCompact()
314+
public static function createCompact(): self
317315
{
318316
$format = self::create();
319317
$format->set('Space*Rules', '')
@@ -327,10 +325,8 @@ public static function createCompact()
327325

328326
/**
329327
* Creates an instance of this class with a preset for pretty formatting.
330-
*
331-
* @return self
332328
*/
333-
public static function createPretty()
329+
public static function createPretty(): self
334330
{
335331
$format = self::create();
336332
$format->set('Space*Rules', "\n")

src/OutputFormatter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,10 @@ public function safely($cCode)
132132
/**
133133
* Clone of the `implode` function, but calls `render` with the current output format instead of `__toString()`.
134134
*
135-
* @param string $sSeparator
136135
* @param array<array-key, Renderable|string> $aValues
137136
* @param bool $bIncreaseLevel
138137
*/
139-
public function implode($sSeparator, array $aValues, $bIncreaseLevel = false): string
138+
public function implode(string $sSeparator, array $aValues, $bIncreaseLevel = false): string
140139
{
141140
$sResult = '';
142141
$oFormat = $this->oFormat;

src/Parsing/Anchor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ class Anchor
1515
private $iPosition;
1616

1717
/**
18-
* @var \Sabberworm\CSS\Parsing\ParserState
18+
* @var ParserState
1919
*/
2020
private $oParserState;
2121

2222
/**
2323
* @param int $iPosition
24-
* @param \Sabberworm\CSS\Parsing\ParserState $oParserState
2524
*/
2625
public function __construct($iPosition, ParserState $oParserState)
2726
{

src/Parsing/ParserState.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,10 @@ public function isEnd(): bool
362362
* @param string $consumeEnd
363363
* @param array<int, Comment> $comments
364364
*
365-
* @return string
366-
*
367365
* @throws UnexpectedEOFException
368366
* @throws UnexpectedTokenException
369367
*/
370-
public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = [])
368+
public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = []): string
371369
{
372370
$aEnd = \is_array($aEnd) ? $aEnd : [$aEnd];
373371
$out = '';

src/RuleSet/RuleSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function parseRuleSet(ParserState $oParserState, RuleSet $oRuleSet
8282
} else {
8383
$oRule = Rule::parse($oParserState);
8484
}
85-
if ($oRule) {
85+
if ($oRule instanceof Rule) {
8686
$oRuleSet->addRule($oRule);
8787
}
8888
}

src/Settings.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public static function create(): Settings
5656
*
5757
* @param bool $bMultibyteSupport
5858
*
59-
* @return self fluent interface
59+
* @return $this fluent interface
6060
*/
61-
public function withMultibyteSupport($bMultibyteSupport = true)
61+
public function withMultibyteSupport($bMultibyteSupport = true): self
6262
{
6363
$this->bMultibyteSupport = $bMultibyteSupport;
6464
return $this;
@@ -69,9 +69,9 @@ public function withMultibyteSupport($bMultibyteSupport = true)
6969
*
7070
* @param string $sDefaultCharset
7171
*
72-
* @return self fluent interface
72+
* @return $this fluent interface
7373
*/
74-
public function withDefaultCharset($sDefaultCharset)
74+
public function withDefaultCharset($sDefaultCharset): self
7575
{
7676
$this->sDefaultCharset = $sDefaultCharset;
7777
return $this;
@@ -82,9 +82,9 @@ public function withDefaultCharset($sDefaultCharset)
8282
*
8383
* @param bool $bLenientParsing
8484
*
85-
* @return self fluent interface
85+
* @return $this fluent interface
8686
*/
87-
public function withLenientParsing($bLenientParsing = true)
87+
public function withLenientParsing($bLenientParsing = true): self
8888
{
8989
$this->bLenientParsing = $bLenientParsing;
9090
return $this;
@@ -93,9 +93,9 @@ public function withLenientParsing($bLenientParsing = true)
9393
/**
9494
* Configures the parser to choke on invalid rules.
9595
*
96-
* @return self fluent interface
96+
* @return $this fluent interface
9797
*/
98-
public function beStrict()
98+
public function beStrict(): self
9999
{
100100
return $this->withLenientParsing(false);
101101
}

src/Value/CSSFunction.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,7 @@ public function __toString(): string
103103
return $this->render(new OutputFormat());
104104
}
105105

106-
/**
107-
* @return string
108-
*/
109-
public function render(OutputFormat $oOutputFormat)
106+
public function render(OutputFormat $oOutputFormat): string
110107
{
111108
$aArguments = parent::render($oOutputFormat);
112109
return "{$this->sName}({$aArguments})";

src/Value/CSSString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function parse(ParserState $oParserState): CSSString
5353
$sContent = null;
5454
if ($sQuote === null) {
5555
// Unquoted strings end in whitespace or with braces, brackets, parentheses
56-
while (!\preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) {
56+
while (\in_array(\preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek()), [0, false], true)) {
5757
$sResult .= $oParserState->parseCharacter(false);
5858
}
5959
} else {

src/Value/Color.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals
111111
*
112112
* @return float
113113
*/
114-
private static function mapRange($fVal, $fFromMin, $fFromMax, $fToMin, $fToMax)
114+
private static function mapRange(float $fVal, float $fFromMin, float $fFromMax, float $fToMin, float $fToMax)
115115
{
116116
$fFromRange = $fFromMax - $fFromMin;
117117
$fToRange = $fToMax - $fToMin;
@@ -151,10 +151,7 @@ public function __toString(): string
151151
return $this->render(new OutputFormat());
152152
}
153153

154-
/**
155-
* @return string
156-
*/
157-
public function render(OutputFormat $oOutputFormat)
154+
public function render(OutputFormat $oOutputFormat): string
158155
{
159156
// Shorthand RGB color values
160157
if ($oOutputFormat->getRGBHashNotation() && \implode('', \array_keys($this->aComponents)) === 'rgb') {

0 commit comments

Comments
 (0)