Skip to content

Commit

Permalink
Adjust CopyInformation to match MODS documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Apr 15, 2024
1 parent 778da7b commit 89e9944
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 50 deletions.
13 changes: 8 additions & 5 deletions src/Mods/Element/Specific/Location/HoldingSimple.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,25 @@ public function __construct(\SimpleXMLElement $xml)
}

/**
* Get the value of the <copyInformation> element.
* Get the the array of the <copyInformation> elements.
* @see https://www.loc.gov/standards/mods/userguide/location.html#copyinformation
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return ?CopyInformation
* @return CopyInformation[]
*/
public function getCopyInformation(string $query = ''): ?CopyInformation
public function getCopyInformation(string $query = ''): array
{
$copyInformation = [];
$xpath = './mods:copyInformation' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new CopyInformation($element->getValues()[0]);
foreach ($element->getValues() as $value) {
$copyInformation[] = new CopyInformation($value);
}
}
return null;
return $copyInformation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ public function __construct(\SimpleXMLElement $xml)
*/
public function getForm(string $query = ''): ?Form
{
$xpath = './mods:form' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new LanguageElement($element->getValues()[0]);
}
return null;
return $this->getLanguageElement('./mods:form' . $query);

Check failure on line 58 in src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Slub\Mods\Element\Specific\Location\HoldingSimple\CopyInformation::getForm() should return Slub\Mods\Element\Specific\PhysicalDescription\Form|null but returns Slub\Mods\Element\Common\LanguageElement|null.
}

/**
Expand All @@ -75,52 +70,42 @@ public function getForm(string $query = ''): ?Form
*/
public function getSubLocations(string $query = ''): array
{
$subLocations = [];
$xpath = './mods:subLocation' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$subLocations[] = new LanguageElement($value);
}
}
return $subLocations;
return $this->getLanguageElements('./mods:subLocation' . $query);
}

/**
* Get the value of the <shelfLocator> element.
* Get the the array of the <shelfLocator> elements.
* @see https://www.loc.gov/standards/mods/userguide/location.html#copyshelflocator
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return LanguageElement
* @return LanguageElement[]
*/
public function getShelfLocator(string $query = ''): LanguageElement
public function getShelfLocators(string $query = ''): array
{
$xpath = './mods:shelfLocator' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new LanguageElement($element->getValues()[0]);
}
return null;
return $this->getLanguageElements('./mods:shelfLocator' . $query);
}

/**
* Get the value of the <electronicLocator> element.
* Get the array of the <electronicLocator> elements.
* @see https://www.loc.gov/standards/mods/userguide/location.html#electroniclocator
*
* @access public
*
* @return string
* @return string[]
*/
public function getElectronicLocator(): string
public function getElectronicLocators(): array
{
$electronicLocators = [];
$element = new Element($this->xml, './mods:electronicLocator');
if ($element->exists()) {
return $element->getValues()[0];
foreach ($element->getValues() as $value) {
$electronicLocators[] = $value;
}
}
return '';
return $electronicLocators;
}

/**
Expand All @@ -147,42 +132,48 @@ public function getNotes(string $query = ''): array
}

/**
* Get the value of the <enumerationAndChronology> element.
* Get the array of the <enumerationAndChronology> element.
* @see https://www.loc.gov/standards/mods/userguide/location.html#enumerationandchronology
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return ?EnumerationAndChronology
* @return EnumerationAndChronology[]
*/
public function getEnumerationAndChronology(string $query = ''): ?EnumerationAndChronology
public function getEnumerationAndChronologies(string $query = ''): array
{
$enumerationAndChronologies = [];
$xpath = './mods:enumerationAndChronology' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new EnumerationAndChronology($element->getValues()[0]);
foreach ($element->getValues() as $value) {
$enumerationAndChronologies[] = new EnumerationAndChronology($value);
}
}
return null;
return $enumerationAndChronologies;
}

/**
* Get the value of the <itemIdentifier> element.
* Get the the array of the <itemIdentifier> elements.
* @see https://www.loc.gov/standards/mods/userguide/location.html#itemidentifier
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return ?ItemIdentifier
* @return ItemIdentifier[]
*/
public function getItemIdentifier(string $query = ''): ?ItemIdentifier
public function getItemIdentifiers(string $query = ''): array
{
$itemIdentifiers = [];
$xpath = './mods:itemIdentifier' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new EnumerationAndChronology($element->getValues()[0]);
foreach ($element->getValues() as $value) {
$itemIdentifiers[] = new ItemIdentifier($value);
}
}
return null;
return $itemIdentifiers;
}
}
13 changes: 7 additions & 6 deletions tests/Mods/ModsReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,13 @@ public function testGetLocationsForBookDocument()
self::assertNotNull($holdingSimple);

$copyInformation = $holdingSimple->getCopyInformation();
self::assertNotNull($copyInformation);
self::assertNotEmpty($copyInformation->getSubLocations());
self::assertEquals('Reading room', $copyInformation->getSubLocations()[0]->getValue());
self::assertEquals('QH511.A1J68', $copyInformation->getShelfLocator()->getValue());
self::assertEquals('1', $copyInformation->getEnumerationAndChronology()->getUnitType());
self::assertEquals('v.1-v.2 1999-2002', $copyInformation->getEnumerationAndChronology()->getValue());
self::assertNotEmpty($copyInformation);
self::assertNotEmpty($copyInformation[0]->getSubLocations());
self::assertEquals('Reading room', $copyInformation[0]->getSubLocations()[0]->getValue());
self::assertNotEmpty($copyInformation[0]->getShelfLocators());
self::assertEquals('QH511.A1J68', $copyInformation[0]->getShelfLocators()[0]->getValue());
self::assertEquals('1', $copyInformation[0]->getEnumerationAndChronologies()[0]->getUnitType());
self::assertEquals('v.1-v.2 1999-2002', $copyInformation[0]->getEnumerationAndChronologies()[0]->getValue());
}

public function testGetLocationsByQueryForBookDocument()
Expand Down

0 comments on commit 89e9944

Please sign in to comment.