CssRule   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
A __construct() 0 5 1
A addDirective() 0 3 1
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