From 52ce1986eb74662f38083427440b5058f2856361 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Thu, 18 Apr 2024 16:34:04 +0200 Subject: [PATCH] Fix remaining PHPStan warnings --- .github/phpstan.neon | 1 + .../Specific/Location/HoldingSimple/CopyInformation.php | 7 ++++++- src/Mods/Element/Specific/Part/Detail.php | 6 +++--- src/Mods/Element/Subject.php | 2 +- src/Mods/Element/TitleInfo.php | 4 ++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/phpstan.neon b/.github/phpstan.neon index 6fc5aad..0aeee55 100644 --- a/.github/phpstan.neon +++ b/.github/phpstan.neon @@ -2,6 +2,7 @@ parameters: ignoreErrors: - '#PHPDoc tag @var for property Slub\\Mods\\Element\\Xml\\Element::\$values with type array\|false is not subtype of native type array\.#' - '#PHPDoc tag @return with type array\|false is not subtype of native type array\.#' + - '#Property Slub\\Mods\\Element\\Specific\\OriginInfo\\Issuance::\$allowedValues is never read, only written\.#' level: 5 paths: - ../src/ diff --git a/src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php b/src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php index e717dc1..b0c1236 100644 --- a/src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php +++ b/src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php @@ -55,7 +55,12 @@ public function __construct(\SimpleXMLElement $xml) */ public function getForm(string $query = ''): ?Form { - return $this->getLanguageElement('./mods:form' . $query); + $xpath = './mods:form' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + return new Form($element->getValues()[0]); + } + return null; } /** diff --git a/src/Mods/Element/Specific/Part/Detail.php b/src/Mods/Element/Specific/Part/Detail.php index fcfb2de..9c4ab49 100644 --- a/src/Mods/Element/Specific/Part/Detail.php +++ b/src/Mods/Element/Specific/Part/Detail.php @@ -72,7 +72,7 @@ public function getLevel(): int * * @param string $query The XPath query for metadata search * - * @return LanguageElement + * @return LanguageElement[] */ public function getNumbers(string $query = ''): array { @@ -87,7 +87,7 @@ public function getNumbers(string $query = ''): array * * @param string $query The XPath query for metadata search * - * @return LanguageElement + * @return LanguageElement[] */ public function getCaptions(string $query = ''): array { @@ -102,7 +102,7 @@ public function getCaptions(string $query = ''): array * * @param string $query The XPath query for metadata search * - * @return LanguageElement + * @return LanguageElement[] */ public function getTitles(string $query = ''): array { diff --git a/src/Mods/Element/Subject.php b/src/Mods/Element/Subject.php index 75f1eb1..51b4339 100644 --- a/src/Mods/Element/Subject.php +++ b/src/Mods/Element/Subject.php @@ -114,7 +114,7 @@ public function getTemporals(string $query = ''): array $element = new Element($this->xml, $xpath); if ($element->exists()) { foreach ($element->getValues() as $value) { - $temporals[] = new AuthorityLanguageElement($value); + $temporals[] = new AuthorityDateLanguageElement($value); } } return $temporals; diff --git a/src/Mods/Element/TitleInfo.php b/src/Mods/Element/TitleInfo.php index 696cb5f..48078ac 100644 --- a/src/Mods/Element/TitleInfo.php +++ b/src/Mods/Element/TitleInfo.php @@ -134,9 +134,9 @@ public function getSubTitle(string $query = ''): ?LanguageElement * * @param string $query The XPath query for metadata search * - * @return LanguageElement + * @return ?LanguageElement */ - public function getPartNumber(string $query = ''): LanguageElement + public function getPartNumber(string $query = ''): ?LanguageElement { $xpath = './mods:partNumber' . $query; $element = new Element($this->xml, $xpath);