CssRule::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/*
4
 * citeproc-php
5
 *
6
 * @link        http://github.com/seboettg/citeproc-php for the source repository
7
 * @copyright   Copyright (c) 2017 Sebastian Böttger.
8
 * @license     https://opensource.org/licenses/MIT
9
 */
10
11
namespace Seboettg\CiteProc\Styles\Css;
12
13
use Seboettg\Collection\Lists\ListInterface;
14
use function Seboettg\Collection\Lists\emptyList;
15
16
/**
17
 * Class CssRule
18
 * @package Seboettg\CiteProc\Styles\Css
19
 * @author Sebastian Böttger <[email protected]>
20
 */
21
class CssRule
22
{
23
    const SELECTOR_TYPE_ID = "#";
24
25
    const SELECTOR_TYPE_CLASS = ".";
26
27
    private string $selectorType;
28
29
    private string $selector;
30
31
    private ListInterface $directives;
32
33
    public function __construct(string $selector, string $selectorType = self::SELECTOR_TYPE_CLASS)
34
    {
35
        $this->selector = $selector;
36
        $this->selectorType = $selectorType;
37
        $this->directives = emptyList();
38
    }
39
40
    public function addDirective(string $property, string $value)
41
    {
42
        $this->directives->add("$property: $value;");
43
    }
44
45
    public function __toString(): string
46
    {
47
        $directives = "\t".implode("\n\t", $this->directives->toArray());
48
        return $this->selectorType.$this->selector." {\n".$directives."\n}\n";
49
    }
50
}
51