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

MyIntervals / PHP-CSS-Parser / 16112982700

07 Jul 2025 09:18AM UTC coverage: 57.935%. Remained the same
16112982700

Pull #1307

github

web-flow
Merge 81b4533d5 into 674cfa00c
Pull Request #1307: [DOCS] Temporarily drop some markers from the class diagram

1055 of 1821 relevant lines covered (57.94%)

16.67 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 non-empty-string
21
     *
22
     * @internal since 8.8.0
23
     */
24
    protected $name;
25

26
    /**
27
     * @param non-empty-string $name
28
     * @param RuleValueList|array<Value|string> $arguments
29
     * @param non-empty-string $separator
30
     * @param int<1, max>|null $lineNumber
31
     */
32
    public function __construct(string $name, $arguments, string $separator = ',', ?int $lineNumber = null)
×
33
    {
34
        if ($arguments instanceof RuleValueList) {
×
35
            $separator = $arguments->getListSeparator();
×
36
            $arguments = $arguments->getListComponents();
×
37
        }
38
        $this->name = $name;
×
39
        $this->setPosition($lineNumber); // TODO: redundant?
×
40
        parent::__construct($arguments, $separator, $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
        $name = self::parseName($parserState, $ignoreCase);
×
53
        $parserState->consume('(');
×
54
        $arguments = self::parseArguments($parserState);
×
55

56
        $result = new CSSFunction($name, $arguments, ',', $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 non-empty-string
86
     */
87
    public function getName(): string
×
88
    {
89
        return $this->name;
×
90
    }
91

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

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

108
    /**
109
     * @return non-empty-string
110
     */
111
    public function render(OutputFormat $outputFormat): string
×
112
    {
113
        $arguments = parent::render($outputFormat);
×
114
        return "{$this->name}({$arguments})";
×
115
    }
116
}
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