PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.4
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.4
2.4.3 2.4.4 2.4.2 2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 All 60 releases
easy-invoice / vendor / sabberworm / php-css-parser / src / Value / CalcFunction.php

CalcFunction.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.4.4, at vendor/sabberworm/php-css-parser/src/Value/CalcFunction.php

116 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sabberworm\CSS\Value;
4
5 use Sabberworm\CSS\Parsing\ParserState;
6 use Sabberworm\CSS\Parsing\UnexpectedEOFException;
7 use Sabberworm\CSS\Parsing\UnexpectedTokenException;
8
9 /**
10 * Support for `-webkit-calc` and `-moz-calc` is deprecated in version 8.8.0, and will be removed in version 9.0.0.
11 */
12 class CalcFunction extends CSSFunction
13 {
14 /**
15 * @var int
16 *
17 * @internal
18 */
19 const T_OPERAND = 1;
20
21 /**
22 * @var int
23 *
24 * @internal
25 */
26 const T_OPERATOR = 2;
27
28 /**
29 * @param ParserState $oParserState
30 * @param bool $bIgnoreCase
31 *
32 * @return CalcFunction
33 *
34 * @throws UnexpectedTokenException
35 * @throws UnexpectedEOFException
36 *
37 * @internal since V8.8.0
38 */
39 public static function parse(ParserState $oParserState, $bIgnoreCase = false)
40 {
41 $aOperators = ['+', '-', '*', '/'];
42 $sFunction = $oParserState->parseIdentifier();
43 if ($oParserState->peek() != '(') {
44 // Found ; or end of line before an opening bracket
45 throw new UnexpectedTokenException('(', $oParserState->peek(), 'literal', $oParserState->currentLine());
46 } elseif (!in_array($sFunction, ['calc', '-moz-calc', '-webkit-calc'])) {
47 // Found invalid calc definition. Example calc (...
48 throw new UnexpectedTokenException('calc', $sFunction, 'literal', $oParserState->currentLine());
49 }
50 $oParserState->consume('(');
51 $oCalcList = new CalcRuleValueList($oParserState->currentLine());
52 $oList = new RuleValueList(',', $oParserState->currentLine());
53 $iNestingLevel = 0;
54 $iLastComponentType = null;
55 while (!$oParserState->comes(')') || $iNestingLevel > 0) {
56 if ($oParserState->isEnd() && $iNestingLevel === 0) {
57 break;
58 }
59
60 $oParserState->consumeWhiteSpace();
61 if ($oParserState->comes('(')) {
62 $iNestingLevel++;
63 $oCalcList->addListComponent($oParserState->consume(1));
64 $oParserState->consumeWhiteSpace();
65 continue;
66 } elseif ($oParserState->comes(')')) {
67 $iNestingLevel--;
68 $oCalcList->addListComponent($oParserState->consume(1));
69 $oParserState->consumeWhiteSpace();
70 continue;
71 }
72 if ($iLastComponentType != CalcFunction::T_OPERAND) {
73 $oVal = Value::parsePrimitiveValue($oParserState);
74 $oCalcList->addListComponent($oVal);
75 $iLastComponentType = CalcFunction::T_OPERAND;
76 } else {
77 if (in_array($oParserState->peek(), $aOperators)) {
78 if (($oParserState->comes('-') || $oParserState->comes('+'))) {
79 if (
80 $oParserState->peek(1, -1) != ' '
81 || !($oParserState->comes('- ')
82 || $oParserState->comes('+ '))
83 ) {
84 throw new UnexpectedTokenException(
85 " {$oParserState->peek()} ",
86 $oParserState->peek(1, -1) . $oParserState->peek(2),
87 'literal',
88 $oParserState->currentLine()
89 );
90 }
91 }
92 $oCalcList->addListComponent($oParserState->consume(1));
93 $iLastComponentType = CalcFunction::T_OPERATOR;
94 } else {
95 throw new UnexpectedTokenException(
96 sprintf(
97 'Next token was expected to be an operand of type %s. Instead "%s" was found.',
98 implode(', ', $aOperators),
99 $oParserState->peek()
100 ),
101 '',
102 'custom',
103 $oParserState->currentLine()
104 );
105 }
106 }
107 $oParserState->consumeWhiteSpace();
108 }
109 $oList->addListComponent($oCalcList);
110 if (!$oParserState->isEnd()) {
111 $oParserState->consume(')');
112 }
113 return new CalcFunction($sFunction, $oList, ',', $oParserState->currentLine());
114 }
115 }
116