Passed
Push — master ( f36a08...6258cd )
by Sebastian
12:50
created

Bibliography::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
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) 2016 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc\Style;
11
12
use Seboettg\CiteProc\CiteProc;
13
use Seboettg\CiteProc\Data\DataList;
14
use Seboettg\CiteProc\Exception\InvalidStylesheetException;
15
use Seboettg\CiteProc\Root\Root;
16
use Seboettg\CiteProc\Style\Options\BibliographyOptions;
17
use SimpleXMLElement;
18
19
/**
20
 * Class Bibliography
21
 *
22
 * The cs:bibliography element describes the formatting of bibliographies, which list one or more bibliographic sources.
23
 * The required cs:layout child element describes how each bibliographic entry should be formatted. cs:layout may be
24
 * preceded by a cs:sort element, which can be used to specify how references within the bibliography should be sorted
25
 * (see Sorting).
26
 *
27
 * @package Seboettg\CiteProc
28
 *
29
 * @author Sebastian Böttger <[email protected]>
30
 */
31
class Bibliography extends StyleElement
32
{
33
    private $node;
34
35
    /**
36
     * Bibliography constructor.
37
     * @param SimpleXMLElement $node
38
     * @param Root $parent
39
     * @throws InvalidStylesheetException
40
     */
41 75
    public function __construct(SimpleXMLElement $node, Root $parent)
42
    {
43 75
        parent::__construct($node, $parent);
44 75
        $this->node = $node;
45 75
        $bibliographyOptions = new BibliographyOptions($node);
46 75
        CiteProc::getContext()->setBibliographySpecificOptions($bibliographyOptions);
47 75
        $this->initInheritableNameAttributes($node);
48 75
    }
49
50
    /**
51
     * @param array|DataList $data
52
     * @param int|null $citationNumber
53
     * @return string
54
     */
55 68
    public function render($data, $citationNumber = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$citationNumber" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$citationNumber"; expected 0 but found 1
Loading history...
56
    {
57 68
        if (!$this->attributesInitialized) {
58
            $this->initInheritableNameAttributes($this->node);
59
        }
60 68
        $subsequentAuthorSubstitute = CiteProc::getContext()
61 68
            ->getBibliographySpecificOptions()
62 68
            ->getSubsequentAuthorSubstitute();
63
64 68
        $subsequentAuthorSubstituteRule = CiteProc::getContext()
65 68
            ->getBibliographySpecificOptions()
66 68
            ->getSubsequentAuthorSubstituteRule();
67
68 68
        if ($subsequentAuthorSubstitute !== null && !empty($subsequentAuthorSubstituteRule)) {
69 12
            CiteProc::getContext()
70 12
                ->getCitationItems()
71 12
                ->setSubsequentAuthorSubstitute($subsequentAuthorSubstitute);
72 12
            CiteProc::getContext()
73 12
                ->getCitationItems()
74 12
                ->setSubsequentAuthorSubstituteRule($subsequentAuthorSubstituteRule);
75
        }
76 68
        return $this->layout->render($data, $citationNumber);
0 ignored issues
show
Bug introduced by
It seems like $citationNumber can also be of type integer; however, parameter $citationItems of Seboettg\CiteProc\Rendering\Layout::render() does only seem to accept Seboettg\Collection\ArrayList|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
        return $this->layout->render($data, /** @scrutinizer ignore-type */ $citationNumber);
Loading history...
Bug Best Practice introduced by
The expression return $this->layout->re...$data, $citationNumber) also could return the type array|string[] which is incompatible with the documented return type string.
Loading history...
77
    }
78
}
79