Handle resources with missing containedInPlace

Check for situation and return empty array.
Do not create unnecessary requests to database but directly return.
This commit is contained in:
Daniel Siepmann 2021-06-08 11:39:53 +02:00
parent eac551e2bc
commit 6b19485a36
3 changed files with 30 additions and 0 deletions

View file

@ -94,6 +94,10 @@ class Parser
];
}
if (isset($jsonLD['schema:containedInPlace']) === false) {
return [];
}
return array_map(function (array $place) {
return $place['@id'];
}, $jsonLD['schema:containedInPlace']);

View file

@ -46,6 +46,10 @@ class TownRepository extends Repository
public function findOneByRemoteIds(array $remoteIds): ?Town
{
if ($remoteIds === []) {
return null;
}
$query = $this->createQuery();
$query->in('remoteId', $remoteIds);

View file

@ -211,6 +211,28 @@ class ParserTest extends TestCase
], $result);
}
/**
* @test
*/
public function returnsContainedInPlaceIdsForNoEntry(): void
{
$genericFields = $this->prophesize(GenericFields::class);
$openingHours = $this->prophesize(OpeningHours::class);
$address = $this->prophesize(Address::class);
$media = $this->prophesize(Media::class);
$subject = new Parser(
$genericFields->reveal(),
$openingHours->reveal(),
$address->reveal(),
$media->reveal()
);
$result = $subject->getContainedInPlaceIds([]);
self::assertSame([], $result);
}
/**
* @test
*/