Skip to content

Commit 875bd71

Browse files
committed
[CLEANUP] Extract CSSFunction methods parseName and parseArguments
Also - Update the `parse` method 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 5a4245f commit 875bd71

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,21 +34,42 @@ public function __construct($sName, $aArguments, $sSeparator = ',', $iLineNo = 0
3434
}
3535

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

5475
/**

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): CSSFunction
25+
public static function parse(ParserState $oParserState, bool $bIgnoreCase = false): CSSFunction
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,13 +23,10 @@ public function __construct(array $aColor, $iLineNo = 0)
2323
}
2424

2525
/**
26-
* @param ParserState $oParserState
27-
* @param bool $bIgnoreCase
28-
*
2926
* @throws UnexpectedEOFException
3027
* @throws UnexpectedTokenException
3128
*/
32-
public static function parse(ParserState $oParserState, $bIgnoreCase = false): CSSFunction
29+
public static function parse(ParserState $oParserState, bool $bIgnoreCase = false): CSSFunction
3330
{
3431
$aColor = [];
3532
if ($oParserState->comes('#')) {

0 commit comments

Comments
 (0)