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

Bibliography::render()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 4
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\Rendering\Layout;
13
use Seboettg\CiteProc\Rendering\RenderingInterface;
14
use Seboettg\CiteProc\Style\Sort\Sort;
15
16
17
/**
18
 * Class Bibliography
19
 *
20
 * The cs:bibliography element describes the formatting of bibliographies, which list one or more bibliographic sources.
21
 * The required cs:layout child element describes how each bibliographic entry should be formatted. cs:layout may be
22
 * preceded by a cs:sort element, which can be used to specify how references within the bibliography should be sorted
23
 * (see Sorting).
24
 *
25
 * @package Seboettg\CiteProc
26
 *
27
 * @author Sebastian Böttger <[email protected]>
28
 */
29
class Bibliography extends StyleElement
30
{
31
    /**
32
     * If set, the value of this attribute replaces names in a bibliographic entry that also occur in the preceding
33
     * entry. The exact method of substitution depends on the value of the subsequent-author-substitute-rule attribute.
34
     * Substitution is limited to the names of the first cs:names element rendered. (Bibliography-specific option)
35
     *
36
     * @var string
37
     */
38
    private $subsequentAuthorSubstitute;
39
40
    /**
41
     * Specifies when and how names are substituted as a result of subsequent-author-substitute.
42
     * (Bibliography-specific option)
43
     *
44
     * @var SubsequentAuthorSubstituteRule
45
     */
46
    private $subsequentAuthorSubstituteRule;
47
48
    private $node;
49
50
    /**
51
     * Bibliography constructor.
52
     * @param \SimpleXMLElement $node
53
     */
54
    public function __construct(\SimpleXMLElement $node)
55
    {
56
        parent::__construct($node);
57
        $this->node = $node;
58
59
        //<bibliography subsequent-author-substitute="---" subsequent-author-substitute-rule="complete-all">
60
        /** @var \SimpleXMLElement $attribute */
61
        foreach ($node->attributes() as $attribute) {
62
            switch ($attribute->getName()) {
63
                case 'subsequent-author-substitute':
64
                    $this->subsequentAuthorSubstitute = (string) $attribute;
65
                    break;
66
                case 'subsequent-author-substitute-rule':
67
                    $this->subsequentAuthorSubstituteRule = new SubsequentAuthorSubstituteRule((string) $attribute);
68
            }
69
        }
70
        $this->initInheritableNameAttributes($node);
71
    }
72
73
    /**
74
     * @param \stdClass $data
75
     * @param int|null $citationNumber
76
     * @return string
77
     */
78
    public function render($data, $citationNumber = null)
79
    {
80
        if (!$this->attributesInitialized) {
81
            $this->initInheritableNameAttributes($this->node);
82
        }
83
84
        if (!empty($this->subsequentAuthorSubstitute) && !empty($this->subsequentAuthorSubstituteRule)) {
85
            CiteProc::getContext()->getCitationItems()->setSubsequentAuthorSubstitute($this->subsequentAuthorSubstitute);
86
            CiteProc::getContext()->getCitationItems()->setSubsequentAuthorSubstituteRule($this->subsequentAuthorSubstituteRule);
87
        }
88
89
        return $this->layout->render($data, $citationNumber);
0 ignored issues
show
Documentation introduced by
$data is of type object<stdClass>, but the function expects a array|object<Seboettg\CiteProc\Data\DataList>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getSubsequentAuthorSubstitute()
96
    {
97
        return $this->subsequentAuthorSubstitute;
98
    }
99
100
    /**
101
     * @return SubsequentAuthorSubstituteRule
102
     */
103
    public function getSubsequentAuthorSubstituteRule()
104
    {
105
        return $this->subsequentAuthorSubstituteRule;
106
    }
107
108
}