Passed
Push — master ( 279db1...661b73 )
by Sebastian
18:02 queued 11:37
created

CssStyle   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 64
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 0 29 8
A __construct() 0 5 1
A render() 0 3 1
1
<?php
2
/*
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
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\CiteProc\Style\Options\BibliographyOptions;
13
14
/**
15
 * Class CssStyle
16
 * @package Seboettg\CiteProc\Styles
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
17
 * @author Sebastian Böttger <[email protected]>
1 ignored issue
show
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 1
Loading history...
18
 */
3 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
19
class CssStyle
20
{
21
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
22
     * @var BibliographyOptions
23
     */
24
    private $bibliographyOptions;
0 ignored issues
show
Coding Style introduced by
Private member variable "bibliographyOptions" must be prefixed with an underscore
Loading history...
25
26
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
27
     * @var CssRules
28
     */
29
    private $cssRules = null;
0 ignored issues
show
Coding Style introduced by
Private member variable "cssRules" must be prefixed with an underscore
Loading history...
30
31
    /**
32
     * CssStyle constructor.
33
     * @param BibliographyOptions $bibliographyOptions
2 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
34
     */
35
    public function __construct(BibliographyOptions $bibliographyOptions)
36
    {
37
        $this->bibliographyOptions = $bibliographyOptions;
38
        $this->cssRules = new CssRules();
39
        $this->init();
40
    }
41
42
    /**
43
     * renders CSS output
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
44
     * @return string
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
45
     */
46
    public function render()
47
    {
48
        return implode("\n", $this->cssRules->toArray());
49
    }
50
51
    /**
52
     * initialize CSS rules
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
53
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
54
    private function init()
1 ignored issue
show
Coding Style introduced by
Private method name "CssStyle::init" must be prefixed with an underscore
Loading history...
55
    {
56
        $lineSpacing = $this->bibliographyOptions->getLineSpacing();
57
        $entrySpacing = $this->bibliographyOptions->getEntrySpacing();
58
        $hangingIndent = $this->bibliographyOptions->getHangingIndent();
59
60
        if ($lineSpacing || $entrySpacing || $hangingIndent) {
61
            $rule = $this->cssRules->getRule(".csl-entry");
62
            if (!empty($lineSpacing)) {
63
                $rule->addDirective("line-height", intval($lineSpacing) . "em");
64
            }
65
66
            if (!empty($entrySpacing)) {
67
                $rule->addDirective("margin-bottom", intval($entrySpacing) . "em");
68
            }
69
70
            if (!empty($hangingIndent)) {
71
                $rule->addDirective("padding-left", "2em");
72
                $rule->addDirective("text-indent", "-2em");
73
            }
74
        }
75
76
        if ("flush" === $this->bibliographyOptions->getSecondFieldAlign()) {
77
            $rule = $this->cssRules->getRule(".csl-left-margin");
78
            $rule->addDirective("display", "block");
79
            $rule->addDirective("float", "left");
80
81
            $rule = $this->cssRules->getRule(".csl-right-inline");
82
            $rule->addDirective("margin-left", "35px");
83
        }
84
    }
85
}
86