• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MyIntervals / PHP-CSS-Parser / 13562750149

27 Feb 2025 09:09AM UTC coverage: 54.784%. Remained the same
13562750149

push

github

web-flow
[TASK] Deprecate `__toString()` (#1006)

Part of #998

1042 of 1902 relevant lines covered (54.78%)

12.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Value/CSSFunction.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Sabberworm\CSS\Value;
6

7
use Sabberworm\CSS\OutputFormat;
8
use Sabberworm\CSS\Parsing\ParserState;
9
use Sabberworm\CSS\Parsing\SourceException;
10
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
11
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
12

13
/**
14
 * A `CSSFunction` represents a special kind of value that also contains a function name and where the values are the
15
 * function’s arguments. It also handles equals-sign-separated argument lists like `filter: alpha(opacity=90);`.
16
 */
17
class CSSFunction extends ValueList
18
{
19
    /**
20
     * @var string
21
     *
22
     * @internal since 8.8.0
23
     */
24
    protected $sName;
25

26
    /**
27
     * @param string $sName
28
     * @param RuleValueList|array<array-key, Value|string> $aArguments
29
     * @param string $sSeparator
30
     * @param int<0, max> $lineNumber
31
     */
32
    public function __construct($sName, $aArguments, $sSeparator = ',', $lineNumber = 0)
×
33
    {
34
        if ($aArguments instanceof RuleValueList) {
×
35
            $sSeparator = $aArguments->getListSeparator();
×
36
            $aArguments = $aArguments->getListComponents();
×
37
        }
38
        $this->sName = $sName;
×
39
        $this->lineNumber = $lineNumber;
×
40
        parent::__construct($aArguments, $sSeparator, $lineNumber);
×
41
    }
×
42

43
    /**
44
     * @throws SourceException
45
     * @throws UnexpectedEOFException
46
     * @throws UnexpectedTokenException
47
     *
48
     * @internal since V8.8.0
49
     */
50
    public static function parse(ParserState $parserState, bool $ignoreCase = false): CSSFunction
×
51
    {
52
        $sName = self::parseName($parserState, $ignoreCase);
×
53
        $parserState->consume('(');
×
54
        $mArguments = self::parseArguments($parserState);
×
55

56
        $result = new CSSFunction($sName, $mArguments, ',', $parserState->currentLine());
×
57
        $parserState->consume(')');
×
58

59
        return $result;
×
60
    }
61

62
    /**
63
     * @throws SourceException
64
     * @throws UnexpectedEOFException
65
     * @throws UnexpectedTokenException
66
     */
67
    private static function parseName(ParserState $parserState, bool $ignoreCase = false): string
×
68
    {
69
        return $parserState->parseIdentifier($ignoreCase);
×
70
    }
71

72
    /**
73
     * @return Value|string
74
     *
75
     * @throws SourceException
76
     * @throws UnexpectedEOFException
77
     * @throws UnexpectedTokenException
78
     */
79
    private static function parseArguments(ParserState $parserState)
×
80
    {
81
        return Value::parseValue($parserState, ['=', ' ', ',']);
×
82
    }
83

84
    /**
85
     * @return string
86
     */
87
    public function getName()
×
88
    {
89
        return $this->sName;
×
90
    }
91

92
    /**
93
     * @param string $sName
94
     */
95
    public function setName($sName): void
×
96
    {
97
        $this->sName = $sName;
×
98
    }
×
99

100
    /**
101
     * @return array<array-key, Value|string>
102
     */
103
    public function getArguments()
×
104
    {
105
        return $this->aComponents;
×
106
    }
107

108
    /**
109
     * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
110
     */
111
    public function __toString(): string
×
112
    {
113
        return $this->render(new OutputFormat());
×
114
    }
115

116
    public function render(OutputFormat $outputFormat): string
×
117
    {
118
        $aArguments = parent::render($outputFormat);
×
119
        return "{$this->sName}({$aArguments})";
×
120
    }
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc