Test Failed
Push — master ( 9d4e41...1cd52c )
by Sebastian
03:24
created

StyleElement::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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\Style;
11
use Seboettg\CiteProc\CiteProc;
12
use Seboettg\CiteProc\Data\DataList;
13
use Seboettg\CiteProc\Rendering\Layout;
14
use Seboettg\CiteProc\Rendering\RenderingInterface;
15
use Seboettg\CiteProc\Style\Sort\Sort;
16
17
18
/**
19
 * Class StyleElement
20
 *
21
 * StyleElement is an abstract class which must be extended by Citation and Bibliography class. The constructor
22
 * of StyleElement class parses the cs:layout element (necessary for cs:citation and cs:bibliography) and the optional
23
 * cs:sort element.
24
 *
25
 * @package Seboettg\CiteProc\Style
26
 *
27
 * @author Sebastian Böttger <[email protected]>
28
 */
29
abstract class StyleElement implements RenderingInterface
30
{
31
32
    use InheritableNameAttributesTrait;
33
    /**
34
     * @var Layout
35
     */
36
    protected $layout;
37
38
    /**
39
     * @var bool
40
     */
41
    protected $doNotSort;
42
43
44
    /**
45
     * Parses the configuration.
46
     *
47
     * @throws \ErrorException If layout is missing
48
     */
49
    protected function __construct(\SimpleXMLElement $node)
50
    {
51
        // init child elements
52
        /** @var \SimpleXMLElement $child */
53
        foreach ($node->children() as $child) {
54
            switch ($child->getName()) {
55
56
                /* The cs:layout rendering element is a required child element of cs:citation and cs:bibliography. It
57
                 * must contain one or more of the other rendering elements described below, and may carry affixes and
58
                 * formatting attributes.
59
                 */
60
                case 'layout':
61
                    $this->layout   =   new Layout($child);
62
                    break;
63
64
                /* cs:citation and cs:bibliography may include a cs:sort child element before the cs:layout element to
65
                 * specify the sorting order of respectively cites within citations, and bibliographic entries within
66
                 * the bibliography. In the absence of cs:sort, cites and bibliographic entries appear in the order in
67
                 * which they are cited.
68
                 */
69
                case 'sort':
70
                    $sorting = new Sort($child);
71
                    CiteProc::getContext()->setSorting($sorting);
72
            }
73
        }
74
    }
75
}