Skip to content

[TASK] Clean up the code with Rector #772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/CSSList/CSSList.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ private static function parseAtRule(ParserState $oParserState)
$sMediaQuery = null;
if (!$oParserState->comes(';')) {
$sMediaQuery = \trim($oParserState->consumeUntil([';', ParserState::EOF]));
if ($sMediaQuery === '') {
$sMediaQuery = null;
}
}
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
return new Import($oLocation, $sMediaQuery ?: null, $iIdentifierLineNum);
return new Import($oLocation, $sMediaQuery, $iIdentifierLineNum);
} elseif ($sIdentifier === 'charset') {
$oCharsetString = CSSString::parse($oParserState);
$oParserState->consumeWhiteSpace();
Expand Down Expand Up @@ -240,9 +243,8 @@ private static function parseAtRule(ParserState $oParserState)
* We need to check for these versions too.
*
* @param string $sIdentifier
* @param string $sMatch
*/
private static function identifierIs($sIdentifier, $sMatch): bool
private static function identifierIs($sIdentifier, string $sMatch): bool
{
return (\strcasecmp($sIdentifier, $sMatch) === 0)
?: \preg_match("/^(-\\w+-)?$sMatch$/i", $sIdentifier) === 1;
Expand Down
13 changes: 4 additions & 9 deletions src/OutputFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,13 @@ public function set($aNames, $mValue)
}

/**
* @param string $sMethodName
* @param array<array-key, mixed> $aArguments
*
* @return mixed
*
* @throws \Exception
*/
public function __call($sMethodName, array $aArguments)
public function __call(string $sMethodName, array $aArguments)
{
if (\strpos($sMethodName, 'set') === 0) {
return $this->set(\substr($sMethodName, 3), $aArguments[0]);
Expand Down Expand Up @@ -303,17 +302,15 @@ public function level()
/**
* Creates an instance of this class without any particular formatting settings.
*/
public static function create(): OutputFormat
public static function create(): self
{
return new OutputFormat();
}

/**
* Creates an instance of this class with a preset for compact formatting.
*
* @return self
*/
public static function createCompact()
public static function createCompact(): self
{
$format = self::create();
$format->set('Space*Rules', '')
Expand All @@ -327,10 +324,8 @@ public static function createCompact()

/**
* Creates an instance of this class with a preset for pretty formatting.
*
* @return self
*/
public static function createPretty()
public static function createPretty(): self
{
$format = self::create();
$format->set('Space*Rules', "\n")
Expand Down
3 changes: 1 addition & 2 deletions src/OutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,10 @@ public function safely($cCode)
/**
* Clone of the `implode` function, but calls `render` with the current output format instead of `__toString()`.
*
* @param string $sSeparator
* @param array<array-key, Renderable|string> $aValues
* @param bool $bIncreaseLevel
*/
public function implode($sSeparator, array $aValues, $bIncreaseLevel = false): string
public function implode(string $sSeparator, array $aValues, $bIncreaseLevel = false): string
{
$sResult = '';
$oFormat = $this->oFormat;
Expand Down
3 changes: 1 addition & 2 deletions src/Parsing/Anchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ class Anchor
private $iPosition;

/**
* @var \Sabberworm\CSS\Parsing\ParserState
* @var ParserState
*/
private $oParserState;

/**
* @param int $iPosition
* @param \Sabberworm\CSS\Parsing\ParserState $oParserState
*/
public function __construct($iPosition, ParserState $oParserState)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Parsing/ParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,10 @@ public function isEnd(): bool
* @param string $consumeEnd
* @param array<int, Comment> $comments
*
* @return string
*
* @throws UnexpectedEOFException
* @throws UnexpectedTokenException
*/
public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = [])
public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = []): string
{
$aEnd = \is_array($aEnd) ? $aEnd : [$aEnd];
$out = '';
Expand Down
2 changes: 1 addition & 1 deletion src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function parseRuleSet(ParserState $oParserState, RuleSet $oRuleSet
} else {
$oRule = Rule::parse($oParserState);
}
if ($oRule) {
if ($oRule instanceof Rule) {
$oRuleSet->addRule($oRule);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public static function create(): Settings
*
* @param bool $bMultibyteSupport
*
* @return self fluent interface
* @return $this fluent interface
*/
public function withMultibyteSupport($bMultibyteSupport = true)
public function withMultibyteSupport($bMultibyteSupport = true): self
{
$this->bMultibyteSupport = $bMultibyteSupport;
return $this;
Expand All @@ -69,9 +69,9 @@ public function withMultibyteSupport($bMultibyteSupport = true)
*
* @param string $sDefaultCharset
*
* @return self fluent interface
* @return $this fluent interface
*/
public function withDefaultCharset($sDefaultCharset)
public function withDefaultCharset($sDefaultCharset): self
{
$this->sDefaultCharset = $sDefaultCharset;
return $this;
Expand All @@ -82,9 +82,9 @@ public function withDefaultCharset($sDefaultCharset)
*
* @param bool $bLenientParsing
*
* @return self fluent interface
* @return $this fluent interface
*/
public function withLenientParsing($bLenientParsing = true)
public function withLenientParsing($bLenientParsing = true): self
{
$this->bLenientParsing = $bLenientParsing;
return $this;
Expand All @@ -93,9 +93,9 @@ public function withLenientParsing($bLenientParsing = true)
/**
* Configures the parser to choke on invalid rules.
*
* @return self fluent interface
* @return $this fluent interface
*/
public function beStrict()
public function beStrict(): self
{
return $this->withLenientParsing(false);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Value/CSSFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ public function __toString(): string
return $this->render(new OutputFormat());
}

/**
* @return string
*/
public function render(OutputFormat $oOutputFormat)
public function render(OutputFormat $oOutputFormat): string
{
$aArguments = parent::render($oOutputFormat);
return "{$this->sName}({$aArguments})";
Expand Down
2 changes: 1 addition & 1 deletion src/Value/CSSString.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function parse(ParserState $oParserState): CSSString
$sContent = null;
if ($sQuote === null) {
// Unquoted strings end in whitespace or with braces, brackets, parentheses
while (!\preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) {
while (\preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek()) !== 1) {
$sResult .= $oParserState->parseCharacter(false);
}
} else {
Expand Down
13 changes: 2 additions & 11 deletions src/Value/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,9 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals
}

/**
* @param float $fVal
* @param float $fFromMin
* @param float $fFromMax
* @param float $fToMin
* @param float $fToMax
*
* @return float
*/
private static function mapRange($fVal, $fFromMin, $fFromMax, $fToMin, $fToMax)
private static function mapRange(float $fVal, float $fFromMin, float $fFromMax, float $fToMin, float $fToMax)
{
$fFromRange = $fFromMax - $fFromMin;
$fToRange = $fToMax - $fToMin;
Expand Down Expand Up @@ -151,10 +145,7 @@ public function __toString(): string
return $this->render(new OutputFormat());
}

/**
* @return string
*/
public function render(OutputFormat $oOutputFormat)
public function render(OutputFormat $oOutputFormat): string
{
// Shorthand RGB color values
if ($oOutputFormat->getRGBHashNotation() && \implode('', \array_keys($this->aComponents)) === 'rgb') {
Expand Down