| Total Complexity | 13 |
| Total Lines | 90 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class Info |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | private $title; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | private $id; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | private $authors; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | private $links; |
||
| 37 | |||
| 38 | 163 | public static function factory(SimpleXMLElement $node): Info |
|
| 39 | { |
||
| 40 | 163 | $authors = []; |
|
| 41 | 163 | $links = []; |
|
| 42 | 163 | $id = null; |
|
| 43 | 163 | $title = null; |
|
| 44 | 163 | foreach ($node->children() as $child) { |
|
| 45 | 161 | switch ($child->getName()) { |
|
| 46 | 161 | case 'author': |
|
| 47 | 161 | case 'contributor': |
|
| 48 | 41 | $author = new stdClass(); |
|
| 49 | /** @var SimpleXMLElement $authorNode */ |
||
| 50 | 41 | foreach ($child->children() as $authorNode) { |
|
| 51 | 41 | $author->{$authorNode->getName()} = (string) $authorNode; |
|
| 52 | } |
||
| 53 | 41 | $authors[] = $author; |
|
| 54 | 41 | break; |
|
| 55 | 161 | case 'link': |
|
| 56 | 41 | $links[] = (string) $child->attributes()['href']; |
|
| 57 | 41 | break; |
|
| 58 | 161 | case 'id': |
|
| 59 | 159 | $id = (string) $child; |
|
| 60 | 159 | break; |
|
| 61 | 161 | case 'title': |
|
| 62 | 161 | $title = (string) $child; |
|
| 63 | } |
||
| 64 | } |
||
| 65 | 163 | return new Info($id, $title, $authors, $links); |
|
| 66 | } |
||
| 67 | |||
| 68 | 163 | public function __construct(?string $id, ?string $title, array $authors, array $links) |
|
| 69 | { |
||
| 70 | 163 | $this->id = $id; |
|
| 71 | 163 | $this->title = $title; |
|
| 72 | 163 | $this->authors = $authors; |
|
| 73 | 163 | $this->links = $links; |
|
| 74 | 163 | } |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | 1 | public function getTitle(): ?string |
|
| 80 | { |
||
| 81 | 1 | return $this->title; |
|
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | 1 | public function getId(): ?string |
|
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @return array |
||
| 94 | */ |
||
| 95 | 1 | public function getAuthors(): array |
|
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return array |
||
| 102 | */ |
||
| 103 | 1 | public function getLinks(): array |
|
| 108 |