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

CssStyle   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A render() 0 4 1
C init() 0 32 8
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\CiteProc\Style\Options\BibliographyOptions;
13
14
/**
15
 * Class CssStyle
16
 * @package Seboettg\CiteProc\Styles
17
 * @author Sebastian Böttger <[email protected]>
18
 */
19
class CssStyle
20
{
21
22
    private $bibliographyOptions;
23
24
    private $cssRules = null;
25
26
    public function __construct(BibliographyOptions $bibliographyOptions)
27
    {
28
        $this->bibliographyOptions = $bibliographyOptions;
29
        $this->cssRules = new CssRules();
30
        $this->init();
31
    }
32
33
    public function render()
34
    {
35
        return implode("\n", $this->cssRules->toArray());
36
    }
37
38
    private function init()
39
    {
40
        //'hanging-indent', 'line-spacing', 'entry-spacing', 'second-field-align'
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
42
        $lineSpacing = $this->bibliographyOptions->getLineSpacing();
43
        $entrySpacing = $this->bibliographyOptions->getEntrySpacing();
44
        $hangingIndent = $this->bibliographyOptions->getHangingIndent();
45
46
        if ($lineSpacing || $entrySpacing || $hangingIndent) {
47
            $rule = $this->cssRules->getRule(".csl-entry");
48
            if (!empty($lineSpacing)) {
49
                $rule->addDirective("line-height", intval($lineSpacing)."em");
50
            }
51
52
            if (!empty($entrySpacing)) {
53
                $rule->addDirective("margin-bottom", intval($entrySpacing)."em");
54
            }
55
56
            if (!empty($hangingIndent)) {
57
                $rule->addDirective("text-indent", "45px");
58
            }
59
        }
60
61
        if ("flush" === $this->bibliographyOptions->getSecondFieldAlign()) {
62
            $rule = $this->cssRules->getRule(".csl-left-margin");
63
            $rule->addDirective("display", "block");
64
            $rule->addDirective("float", "left");
65
66
            $rule = $this->cssRules->getRule(".csl-right-inline");
67
            $rule->addDirective("margin-left", "35px");
68
        }
69
    }
70
}