Skip to content

Commit 8b226e0

Browse files
committed
[CLEANUP] Extract CSSFunction methods parseName and parseArguments
Also - Update the `parse` function signature to use PHP7 type hints; - Remove subsequently redundant DocBlock entries; - Ditto for same-named method in subclasses to avoid contravariance. This is the refactoring change from #390.
1 parent 3163c9f commit 8b226e0

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

src/Value/CSSFunction.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,44 @@ public function __construct($sName, $aArguments, $sSeparator = ',', $iLineNo = 0
3434
}
3535

3636
/**
37-
* @param ParserState $oParserState
38-
* @param bool $bIgnoreCase
39-
*
4037
* @return CSSFunction
4138
*
4239
* @throws SourceException
4340
* @throws UnexpectedEOFException
4441
* @throws UnexpectedTokenException
4542
*/
46-
public static function parse(ParserState $oParserState, $bIgnoreCase = false)
43+
public static function parse(ParserState $oParserState, bool $bIgnoreCase = false): object
4744
{
48-
$mResult = $oParserState->parseIdentifier($bIgnoreCase);
45+
$sName = self::parseName($oParserState, $bIgnoreCase);
4946
$oParserState->consume('(');
50-
$aArguments = Value::parseValue($oParserState, ['=', ' ', ',']);
51-
$mResult = new CSSFunction($mResult, $aArguments, ',', $oParserState->currentLine());
47+
$mArguments = self::parseArguments($oParserState);
48+
49+
$oResult = new CSSFunction($sName, $mArguments, ',', $oParserState->currentLine());
5250
$oParserState->consume(')');
53-
return $mResult;
51+
52+
return $oResult;
53+
}
54+
55+
/**
56+
* @throws SourceException
57+
* @throws UnexpectedEOFException
58+
* @throws UnexpectedTokenException
59+
*/
60+
private static function parseName(ParserState $oParserState, bool $bIgnoreCase = false): string
61+
{
62+
return $oParserState->parseIdentifier($bIgnoreCase);
63+
}
64+
65+
/**
66+
* @return Value|string
67+
*
68+
* @throws SourceException
69+
* @throws UnexpectedEOFException
70+
* @throws UnexpectedTokenException
71+
*/
72+
private static function parseArguments(ParserState $oParserState)
73+
{
74+
return Value::parseValue($oParserState, ['=', ' ', ',']);
5475
}
5576

5677
/**

src/Value/CalcFunction.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ class CalcFunction extends CSSFunction
1919
private const T_OPERATOR = 2;
2020

2121
/**
22-
* @param ParserState $oParserState
23-
* @param bool $bIgnoreCase
24-
*
2522
* @throws UnexpectedTokenException
2623
* @throws UnexpectedEOFException
2724
*/
28-
public static function parse(ParserState $oParserState, $bIgnoreCase = false): CalcFunction
25+
public static function parse(ParserState $oParserState, bool $bIgnoreCase = false): CalcFunction
2926
{
3027
$aOperators = ['+', '-', '*', '/'];
3128
$sFunction = $oParserState->parseIdentifier();

src/Value/Color.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ public function __construct(array $aColor, $iLineNo = 0)
2323
}
2424

2525
/**
26-
* @param ParserState $oParserState
27-
* @param bool $bIgnoreCase
28-
*
2926
* @return Color|CSSFunction
3027
*
3128
* @throws UnexpectedEOFException
3229
* @throws UnexpectedTokenException
3330
*/
34-
public static function parse(ParserState $oParserState, $bIgnoreCase = false)
31+
public static function parse(ParserState $oParserState, bool $bIgnoreCase = false): object
3532
{
3633
$aColor = [];
3734
if ($oParserState->comes('#')) {

0 commit comments

Comments
 (0)