Completed
Push — master ( 0bb17e...5a7e4d )
by Sebastian
04:41
created

CssRule::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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