| Total Complexity | 14 |
| Total Lines | 85 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 48 | class Substitute implements Rendering |
||
| 49 | { |
||
| 50 | |||
| 51 | /** |
||
|
1 ignored issue
–
show
|
|||
| 52 | * @var ArrayList |
||
| 53 | */ |
||
| 54 | private $children; |
||
| 55 | |||
| 56 | /** |
||
|
1 ignored issue
–
show
|
|||
| 57 | * @var Names |
||
| 58 | */ |
||
| 59 | private $parent; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Substitute constructor. |
||
| 63 | * @param SimpleXMLElement $node |
||
|
3 ignored issues
–
show
|
|||
| 64 | * @param Names $parent |
||
|
3 ignored issues
–
show
|
|||
| 65 | * @throws InvalidStylesheetException |
||
|
1 ignored issue
–
show
|
|||
| 66 | * @throws InvalidStylesheetException |
||
|
1 ignored issue
–
show
|
|||
| 67 | */ |
||
| 68 | public function __construct(SimpleXMLElement $node, Names $parent) |
||
| 69 | { |
||
| 70 | $this->parent = $parent; |
||
| 71 | $this->children = new ArrayList(); |
||
| 72 | foreach ($node->children() as $child) { |
||
| 73 | |||
| 74 | /** @var SimpleXMLElement $child */ |
||
|
3 ignored issues
–
show
|
|||
| 75 | if ($child->getName() === "names") { |
||
| 76 | |||
| 77 | /** @var Names $names */ |
||
|
3 ignored issues
–
show
|
|||
| 78 | $names = Factory::create($child, $this); |
||
| 79 | |||
| 80 | /* A shorthand version of cs:names without child elements, which inherits the attributes values set on |
||
| 81 | the cs:name and cs:et-al child elements of the original cs:names element, may also be used. */ |
||
| 82 | if (!$names->hasEtAl()) { |
||
| 83 | // inherit et-al |
||
| 84 | if ($this->parent->hasEtAl()) { |
||
| 85 | $names->setEtAl($this->parent->getEtAl()); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | if (!$names->hasName()) { |
||
| 89 | // inherit name |
||
| 90 | if ($this->parent->hasName()) { |
||
| 91 | $names->setName($this->parent->getName()); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | // inherit label |
||
| 95 | if (!$names->hasLabel() && $this->parent->hasLabel()) { |
||
| 96 | $names->setLabel($this->parent->getLabel()); |
||
| 97 | } |
||
| 98 | |||
| 99 | $this->children->append($names); |
||
| 100 | } else { |
||
| 101 | $object = Factory::create($child, $this); |
||
| 102 | $this->children->append($object); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
|
1 ignored issue
–
show
|
|||
| 108 | * @param stdClass $data |
||
|
2 ignored issues
–
show
|
|||
| 109 | * @param int|null $citationNumber |
||
|
2 ignored issues
–
show
|
|||
| 110 | * @return string |
||
|
1 ignored issue
–
show
|
|||
| 111 | */ |
||
| 112 | public function render($data, $citationNumber = null) |
||
| 133 | } |
||
| 134 | } |
||
| 135 |