Skip to content

Commit 2c49003

Browse files
authored
[TASK] Clean up the code with Rector (#772)
Just the Rector changes, and some redundancy removal related to those, but nothing more.
1 parent fa7a20e commit 2c49003

File tree

10 files changed

+25
-44
lines changed

10 files changed

+25
-44
lines changed

src/CSSList/CSSList.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,12 @@ private static function parseAtRule(ParserState $oParserState)
167167
$sMediaQuery = null;
168168
if (!$oParserState->comes(';')) {
169169
$sMediaQuery = \trim($oParserState->consumeUntil([';', ParserState::EOF]));
170+
if ($sMediaQuery === '') {
171+
$sMediaQuery = null;
172+
}
170173
}
171174
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
172-
return new Import($oLocation, $sMediaQuery ?: null, $iIdentifierLineNum);
175+
return new Import($oLocation, $sMediaQuery, $iIdentifierLineNum);
173176
} elseif ($sIdentifier === 'charset') {
174177
$oCharsetString = CSSString::parse($oParserState);
175178
$oParserState->consumeWhiteSpace();
@@ -240,9 +243,8 @@ private static function parseAtRule(ParserState $oParserState)
240243
* We need to check for these versions too.
241244
*
242245
* @param string $sIdentifier
243-
* @param string $sMatch
244246
*/
245-
private static function identifierIs($sIdentifier, $sMatch): bool
247+
private static function identifierIs($sIdentifier, string $sMatch): bool
246248
{
247249
return (\strcasecmp($sIdentifier, $sMatch) === 0)
248250
?: \preg_match("/^(-\\w+-)?$sMatch$/i", $sIdentifier) === 1;

src/OutputFormat.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,13 @@ public function set($aNames, $mValue)
223223
}
224224

225225
/**
226-
* @param string $sMethodName
227226
* @param array<array-key, mixed> $aArguments
228227
*
229228
* @return mixed
230229
*
231230
* @throws \Exception
232231
*/
233-
public function __call($sMethodName, array $aArguments)
232+
public function __call(string $sMethodName, array $aArguments)
234233
{
235234
if (\strpos($sMethodName, 'set') === 0) {
236235
return $this->set(\substr($sMethodName, 3), $aArguments[0]);
@@ -303,17 +302,15 @@ public function level()
303302
/**
304303
* Creates an instance of this class without any particular formatting settings.
305304
*/
306-
public static function create(): OutputFormat
305+
public static function create(): self
307306
{
308307
return new OutputFormat();
309308
}
310309

311310
/**
312311
* Creates an instance of this class with a preset for compact formatting.
313-
*
314-
* @return self
315312
*/
316-
public static function createCompact()
313+
public static function createCompact(): self
317314
{
318315
$format = self::create();
319316
$format->set('Space*Rules', '')
@@ -327,10 +324,8 @@ public static function createCompact()
327324

328325
/**
329326
* Creates an instance of this class with a preset for pretty formatting.
330-
*
331-
* @return self
332327
*/
333-
public static function createPretty()
328+
public static function createPretty(): self
334329
{
335330
$format = self::create();
336331
$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 (\preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek()) !== 1) {
5757
$sResult .= $oParserState->parseCharacter(false);
5858
}
5959
} else {

src/Value/Color.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,9 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals
103103
}
104104

105105
/**
106-
* @param float $fVal
107-
* @param float $fFromMin
108-
* @param float $fFromMax
109-
* @param float $fToMin
110-
* @param float $fToMax
111-
*
112106
* @return float
113107
*/
114-
private static function mapRange($fVal, $fFromMin, $fFromMax, $fToMin, $fToMax)
108+
private static function mapRange(float $fVal, float $fFromMin, float $fFromMax, float $fToMin, float $fToMax)
115109
{
116110
$fFromRange = $fFromMax - $fFromMin;
117111
$fToRange = $fToMax - $fToMin;
@@ -151,10 +145,7 @@ public function __toString(): string
151145
return $this->render(new OutputFormat());
152146
}
153147

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

0 commit comments

Comments
 (0)