DisplayTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A wrapDisplayBlock() 0 7 2
A initDisplayAttributes() 0 7 3
1
<?php
2
/*
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc\Styles;
11
12
use SimpleXMLElement;
13
14
/**
15
 * Trait DisplayTrait
16
 * @package Seboettg\CiteProc\Styles
17
 * @author Sebastian Böttger <[email protected]>
18
 */
19
trait DisplayTrait
20
{
21
22
    /**
23
     * @var array
24
     */
25
    private static $allowedValues = [
26
        "block",
27
        "left-margin",
28
        "right-inline",
29
        "indent"
30
    ];
31
32
    /**
33
     * @var string
34
     */
35
    private $display;
36
37
    /**
38
     * @param $node
39
     */
40
    public function initDisplayAttributes(SimpleXMLElement $node)
41
    {
42
        foreach ($node->attributes() as $attribute) {
43
            switch ($attribute->getName()) {
44
                case 'display':
45
                    $this->display = (string) $attribute;
46
                    return;
47
            }
48
        }
49
    }
50
51
    /**
52
     * @param $text
53
     * @return string
54
     */
55
    public function wrapDisplayBlock($text)
56
    {
57
        if (!in_array($this->display, self::$allowedValues)) {
58
            return $text;
59
        }
60
        $divStyle = "class=\"csl-".$this->display."\"";
61
        return "<div $divStyle>$text</div>";
62
    }
63
}
64