From 75f8e3b8ae7bcdcb25476fe84aba5c035423f78b Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Wed, 19 Jun 2024 19:29:57 +0200 Subject: [PATCH 1/2] [CLEANUP] Rector: Add return type to function like with return new This applies the rule ReturnTypeFromReturnNewRector. For Details see: https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#returntypefromreturnnewrector Signed-off-by: Daniel Ziegenberg --- src/CSSList/Document.php | 2 +- src/OutputFormat.php | 4 +--- src/Parsing/ParserState.php | 7 +++---- src/Rule/Rule.php | 4 +--- src/Settings.php | 2 +- src/Value/CSSString.php | 4 +--- src/Value/CalcFunction.php | 4 +--- src/Value/LineName.php | 4 +--- src/Value/Size.php | 4 +--- src/Value/URL.php | 4 +--- src/Value/Value.php | 5 ++--- 11 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/CSSList/Document.php b/src/CSSList/Document.php index 145d0617..fa1cb4bd 100644 --- a/src/CSSList/Document.php +++ b/src/CSSList/Document.php @@ -29,7 +29,7 @@ public function __construct($iLineNo = 0) * * @throws SourceException */ - public static function parse(ParserState $oParserState) + public static function parse(ParserState $oParserState): Document { $oDocument = new Document($oParserState->currentLine()); CSSList::parseList($oParserState, $oDocument); diff --git a/src/OutputFormat.php b/src/OutputFormat.php index 9cc2ae4d..81026b2a 100644 --- a/src/OutputFormat.php +++ b/src/OutputFormat.php @@ -303,10 +303,8 @@ public function level() /** * Creates an instance of this class without any particular formatting settings. - * - * @return self */ - public static function create() + public static function create(): OutputFormat { return new OutputFormat(); } diff --git a/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index e5f216a4..13b0fce8 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -3,6 +3,7 @@ namespace Sabberworm\CSS\Parsing; use Sabberworm\CSS\Comment\Comment; +use Sabberworm\CSS\Parsing\Anchor; use Sabberworm\CSS\Settings; class ParserState @@ -114,10 +115,8 @@ public function getSettings() return $this->oParserSettings; } - /** - * @return \Sabberworm\CSS\Parsing\Anchor - */ - public function anchor() + + public function anchor(): Anchor { return new Anchor($this->iCurrentPosition, $this); } diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index 163fde0f..19a005bd 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -71,12 +71,10 @@ public function __construct($sRule, $iLineNo = 0, $iColNo = 0) } /** - * @return Rule - * * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parse(ParserState $oParserState) + public static function parse(ParserState $oParserState): Rule { $aComments = $oParserState->consumeWhiteSpace(); $oRule = new Rule( diff --git a/src/Settings.php b/src/Settings.php index 79d99803..831866ce 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -41,7 +41,7 @@ private function __construct() /** * @return self new instance */ - public static function create() + public static function create(): Settings { return new Settings(); } diff --git a/src/Value/CSSString.php b/src/Value/CSSString.php index 8988d5e6..048cf021 100644 --- a/src/Value/CSSString.php +++ b/src/Value/CSSString.php @@ -31,13 +31,11 @@ public function __construct($sString, $iLineNo = 0) } /** - * @return CSSString - * * @throws SourceException * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parse(ParserState $oParserState) + public static function parse(ParserState $oParserState): CSSString { $sBegin = $oParserState->peek(); $sQuote = null; diff --git a/src/Value/CalcFunction.php b/src/Value/CalcFunction.php index f06d9b7e..c7a209d6 100644 --- a/src/Value/CalcFunction.php +++ b/src/Value/CalcFunction.php @@ -22,12 +22,10 @@ class CalcFunction extends CSSFunction * @param ParserState $oParserState * @param bool $bIgnoreCase * - * @return CalcFunction - * * @throws UnexpectedTokenException * @throws UnexpectedEOFException */ - public static function parse(ParserState $oParserState, $bIgnoreCase = false) + public static function parse(ParserState $oParserState, $bIgnoreCase = false): CalcFunction { $aOperators = ['+', '-', '*', '/']; $sFunction = $oParserState->parseIdentifier(); diff --git a/src/Value/LineName.php b/src/Value/LineName.php index c8c1e33a..b4ba6b44 100644 --- a/src/Value/LineName.php +++ b/src/Value/LineName.php @@ -19,12 +19,10 @@ public function __construct(array $aComponents = [], $iLineNo = 0) } /** - * @return LineName - * * @throws UnexpectedTokenException * @throws UnexpectedEOFException */ - public static function parse(ParserState $oParserState) + public static function parse(ParserState $oParserState): LineName { $oParserState->consume('['); $oParserState->consumeWhiteSpace(); diff --git a/src/Value/Size.php b/src/Value/Size.php index b8321fd8..c0c384ce 100644 --- a/src/Value/Size.php +++ b/src/Value/Size.php @@ -71,12 +71,10 @@ public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $ /** * @param bool $bIsColorComponent * - * @return Size - * * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parse(ParserState $oParserState, $bIsColorComponent = false) + public static function parse(ParserState $oParserState, $bIsColorComponent = false): Size { $sSize = ''; if ($oParserState->comes('-')) { diff --git a/src/Value/URL.php b/src/Value/URL.php index f0196c75..43c6aa59 100644 --- a/src/Value/URL.php +++ b/src/Value/URL.php @@ -28,13 +28,11 @@ public function __construct(CSSString $oURL, $iLineNo = 0) } /** - * @return URL - * * @throws SourceException * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parse(ParserState $oParserState) + public static function parse(ParserState $oParserState): URL { $oAnchor = $oParserState->anchor(); $sIdentifier = ''; diff --git a/src/Value/Value.php b/src/Value/Value.php index 3aad2041..4950e35a 100644 --- a/src/Value/Value.php +++ b/src/Value/Value.php @@ -6,6 +6,7 @@ use Sabberworm\CSS\Parsing\SourceException; use Sabberworm\CSS\Parsing\UnexpectedEOFException; use Sabberworm\CSS\Parsing\UnexpectedTokenException; +use Sabberworm\CSS\Value\CSSFunction; use Sabberworm\CSS\Renderable; /** @@ -170,12 +171,10 @@ public static function parsePrimitiveValue(ParserState $oParserState) } /** - * @return CSSFunction - * * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - private static function parseMicrosoftFilter(ParserState $oParserState) + private static function parseMicrosoftFilter(ParserState $oParserState): CSSFunction { $sFunction = $oParserState->consumeUntil('(', false, true); $aArguments = Value::parseValue($oParserState, [',', '=']); From 77c7489a6504cfdfed28f34d1f1ed8e65f307ed8 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Thu, 20 Jun 2024 00:02:38 +0200 Subject: [PATCH 2/2] fixup! [CLEANUP] Rector: Add return type to function like with return new --- src/CSSList/Document.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CSSList/Document.php b/src/CSSList/Document.php index fa1cb4bd..2478b34e 100644 --- a/src/CSSList/Document.php +++ b/src/CSSList/Document.php @@ -25,8 +25,6 @@ public function __construct($iLineNo = 0) } /** - * @return Document - * * @throws SourceException */ public static function parse(ParserState $oParserState): Document