Skip to content

Commit

Permalink
Merge pull request #19 from beatrycze-volk/check-array
Browse files Browse the repository at this point in the history
Check for values existence in `getValues()` function
  • Loading branch information
beatrycze-volk authored Jun 17, 2024
2 parents e3e49eb + dbcb392 commit 98a7145
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 335 deletions.
2 changes: 0 additions & 2 deletions .github/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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:
Expand Down
18 changes: 6 additions & 12 deletions src/Mods/Element/Common/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ protected function getAuthorityLanguageElements(string $xpath): array
{
$elements = [];
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$elements[] = new AuthorityLanguageElement($value);
}
foreach ($element->getValues() as $value) {
$elements[] = new AuthorityLanguageElement($value);
}
return $elements;
}
Expand All @@ -90,10 +88,8 @@ protected function getDateElements(string $xpath): array
{
$elements = [];
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$elements[] = new DateElement($value);
}
foreach ($element->getValues() as $value) {
$elements[] = new DateElement($value);
}
return $elements;
}
Expand Down Expand Up @@ -129,10 +125,8 @@ protected function getLanguageElements(string $xpath): array
{
$elements = [];
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$elements[] = new LanguageElement($value);
}
foreach ($element->getValues() as $value) {
$elements[] = new LanguageElement($value);
}
return $elements;
}
Expand Down
12 changes: 4 additions & 8 deletions src/Mods/Element/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ public function getLanguageTerms(string $query = ''): array
$languageTerms = [];
$xpath = './mods:languageTerm' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$languageTerms[] = new LanguageTerm($value);
}
foreach ($element->getValues() as $value) {
$languageTerms[] = new LanguageTerm($value);
}
return $languageTerms;
}
Expand All @@ -97,10 +95,8 @@ public function getScriptTerms(string $query = ''): array
$scriptTerms = [];
$xpath = './mods:scriptTerm' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$scriptTerms[] = new ScriptTerm($value);
}
foreach ($element->getValues() as $value) {
$scriptTerms[] = new ScriptTerm($value);
}
return $scriptTerms;
}
Expand Down
12 changes: 4 additions & 8 deletions src/Mods/Element/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ public function getPhysicalLocations(string $query = ''): array
$physicalLocations = [];
$xpath = './mods:physicalLocation' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$physicalLocations[] = new PhysicalLocation($value);
}
foreach ($element->getValues() as $value) {
$physicalLocations[] = new PhysicalLocation($value);
}
return $physicalLocations;
}
Expand Down Expand Up @@ -105,10 +103,8 @@ public function getUrls(string $query = ''): array
$urls = [];
$xpath = './mods:url' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$urls[] = new Url($value);
}
foreach ($element->getValues() as $value) {
$urls[] = new Url($value);
}
return $urls;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Mods/Element/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ public function getAlternativeNames(string $query = ''): array
$alternativeNames = [];
$xpath = './mods:alternativeName' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$alternativeNames[] = new AlternativeName($value);
}
foreach ($element->getValues() as $value) {
$alternativeNames[] = new AlternativeName($value);
}
return $alternativeNames;
}
Expand Down
42 changes: 14 additions & 28 deletions src/Mods/Element/OriginInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ public function getPlaces(string $query = ''): array
$places = [];
$xpath = './mods:place' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$places[] = new Place($value);
}
foreach ($element->getValues() as $value) {
$places[] = new Place($value);
}
return $places;
}
Expand All @@ -115,10 +113,8 @@ public function getAgents(string $query = ''): array
$agents = [];
$xpath = './mods:agent' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$agents[] = new Agent($value);
}
foreach ($element->getValues() as $value) {
$agents[] = new Agent($value);
}
return $agents;
}
Expand Down Expand Up @@ -228,10 +224,8 @@ public function getOtherDates(string $query = ''): array
$otherDates = [];
$xpath = './mods:dateOther' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$otherDates[] = new DateOther($value);
}
foreach ($element->getValues() as $value) {
$otherDates[] = new DateOther($value);
}
return $otherDates;
}
Expand All @@ -251,10 +245,8 @@ public function getDisplayDates(string $query = ''): array
$displayDates = [];
$xpath = './mods:displayDate' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$displayDates[] = new DisplayDate($value);
}
foreach ($element->getValues() as $value) {
$displayDates[] = new DisplayDate($value);
}
return $displayDates;
}
Expand All @@ -274,10 +266,8 @@ public function getEditions(string $query = ''): array
$editions = [];
$xpath = './mods:edition' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$editions[] = new Edition($value);
}
foreach ($element->getValues() as $value) {
$editions[] = new Edition($value);
}
return $editions;
}
Expand All @@ -297,10 +287,8 @@ public function getIssuances(string $query = ''): array
$issuances = [];
$xpath = './mods:issuance' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$issuances[] = new Issuance($value);
}
foreach ($element->getValues() as $value) {
$issuances[] = new Issuance($value);
}
return $issuances;
}
Expand All @@ -320,10 +308,8 @@ public function getFrequencies(string $query = ''): array
$frequencies = [];
$xpath = './mods:frequency' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$frequencies[] = new Frequency($value);
}
foreach ($element->getValues() as $value) {
$frequencies[] = new Frequency($value);
}
return $frequencies;
}
Expand Down
18 changes: 6 additions & 12 deletions src/Mods/Element/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ public function getDetails(string $query = ''): array
$details = [];
$xpath = './mods:detail' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$details[] = new Detail($value);
}
foreach ($element->getValues() as $value) {
$details[] = new Detail($value);
}
return $details;
}
Expand All @@ -111,10 +109,8 @@ public function getExtents(string $query = ''): array
$extents = [];
$xpath = './mods:extent' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$extents[] = new Extent($value);
}
foreach ($element->getValues() as $value) {
$extents[] = new Extent($value);
}
return $extents;
}
Expand Down Expand Up @@ -149,10 +145,8 @@ public function getTexts(string $query = ''): array
$texts = [];
$xpath = './mods:text' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$texts[] = new Text($value);
}
foreach ($element->getValues() as $value) {
$texts[] = new Text($value);
}
return $texts;
}
Expand Down
30 changes: 10 additions & 20 deletions src/Mods/Element/PhysicalDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ public function getForms(string $query = ''): array
$forms = [];
$xpath = './mods:form' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$forms[] = new Form($value);
}
foreach ($element->getValues() as $value) {
$forms[] = new Form($value);
}
return $forms;
}
Expand All @@ -86,10 +84,8 @@ public function getReformattingQualities(string $query = ''): array
$reformattingQualities = [];
$xpath = './mods:reformattingQuality' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$reformattingQualities[] = $value;
}
foreach ($element->getValues() as $value) {
$reformattingQualities[] = $value;
}
return $reformattingQualities;
}
Expand Down Expand Up @@ -123,10 +119,8 @@ public function getExtents(string $query = ''): array
$forms = [];
$xpath = './mods:extent' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$forms[] = new Extent($value);
}
foreach ($element->getValues() as $value) {
$forms[] = new Extent($value);
}
return $forms;
}
Expand All @@ -146,10 +140,8 @@ public function getDigitalOrigins(string $query = ''): array
$digitalOrigins = [];
$xpath = './mods:digitalOrigin' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$digitalOrigins[] = $value;
}
foreach ($element->getValues() as $value) {
$digitalOrigins[] = $value;
}
return $digitalOrigins;
}
Expand All @@ -169,10 +161,8 @@ public function getNotes(string $query = ''): array
$notes = [];
$xpath = './mods:note' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$notes[] = new Note($value);
}
foreach ($element->getValues() as $value) {
$notes[] = new Note($value);
}
return $notes;
}
Expand Down
24 changes: 8 additions & 16 deletions src/Mods/Element/RecordInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ public function getRecordIdentifiers(string $query = ''): array
$recordIdentifiers = [];
$xpath = './mods:recordIdentifier' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$recordIdentifiers[] = new RecordIdentifier($value);
}
foreach ($element->getValues() as $value) {
$recordIdentifiers[] = new RecordIdentifier($value);
}
return $recordIdentifiers;
}
Expand All @@ -133,10 +131,8 @@ public function getRecordOrigins(string $query = ''): array
$recordOrigins = [];
$xpath = './mods:recordOrigin' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$recordOrigins[] = new LanguageElement($value);
}
foreach ($element->getValues() as $value) {
$recordOrigins[] = new LanguageElement($value);
}
return $recordOrigins;
}
Expand All @@ -156,10 +152,8 @@ public function getRecordInfoNotes(string $query = ''): array
$recordInfoNotes = [];
$xpath = './mods:recordInfoNote' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$recordInfoNotes[] = new RecordInfoNote($value);
}
foreach ($element->getValues() as $value) {
$recordInfoNotes[] = new RecordInfoNote($value);
}
return $recordInfoNotes;
}
Expand All @@ -179,10 +173,8 @@ public function getLanguageOfCatalogings(string $query = ''): array
$languageOfCatalogings = [];
$xpath = './mods:languageOfCataloging' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$languageOfCatalogings[] = new LanguageOfCataloging($value);
}
foreach ($element->getValues() as $value) {
$languageOfCatalogings[] = new LanguageOfCataloging($value);
}
return $languageOfCatalogings;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Mods/Element/Specific/Location/HoldingSimple.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ public function getCopyInformation(string $query = ''): array
$copyInformation = [];
$xpath = './mods:copyInformation' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$copyInformation[] = new CopyInformation($value);
}
foreach ($element->getValues() as $value) {
$copyInformation[] = new CopyInformation($value);
}
return $copyInformation;
}
Expand Down
Loading

0 comments on commit 98a7145

Please sign in to comment.