Skip to content

Commit

Permalink
fixed PHPStan complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
k00ni committed Oct 28, 2024
1 parent 66cd17e commit b0bc3fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 8 additions & 3 deletions scripts/src/Extractor/AbstractExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\TemporaryIndex;
use EasyRdf\Format;
use Exception;
use PhpParser\Error;
use quickRdfIo\Raptor\Parser;
use quickRdfIo\RdfIoException;
use quickRdfIo\Util;
Expand Down Expand Up @@ -126,7 +127,7 @@ public function addFurtherMetadata(IndexEntry $indexEntry, Graph $graph): void

// create a list of date strings
$values = array_map(function ($value) {
if(1 === preg_match('/[0-9]{4}\-[0-9]{2}\-[0-9]{4}/', $value)) {
if (1 === preg_match('/[0-9]{4}\-[0-9]{2}\-[0-9]{4}/', $value)) {
return $value;
}
}, $values);
Expand All @@ -149,7 +150,7 @@ public function addFurtherMetadata(IndexEntry $indexEntry, Graph $graph): void
$values = $graph->getPropertyValues((string) $indexEntry->getOntologyIri(), $prop);
// create a list of date strings
$values = array_map(function ($value) {
if(1 === preg_match('/[0-9]{4}\-[0-9]{2}\-[0-9]{4}/', $value)) {
if (1 === preg_match('/[0-9]{4}\-[0-9]{2}\-[0-9]{4}/', $value)) {
return $value;
}
}, $values);
Expand Down Expand Up @@ -345,6 +346,10 @@ protected function readQuadsToList($input, string|null $format = null): array
$input = Util::parse($input, $this->dataFactory, $format);
}

if (false === is_iterable($input)) {
throw new Error('$input must be iterable to continue.');
}

/*
* use quickRdfIo's Util::parse
*/
Expand Down Expand Up @@ -413,7 +418,7 @@ protected function loadQuadsIntoGraph($fileHandle, string $localFilePath, string
$list = $this->readQuadsToList($iterator, 'ntriples');
fclose($fileHandle);
return new Graph($list);
} catch(Throwable $th) {
} catch (Throwable $th) {
echo PHP_EOL;
echo PHP_EOL.'- ERR: '.$th->getMessage();
echo PHP_EOL;
Expand Down
7 changes: 7 additions & 0 deletions scripts/src/Extractor/DBpediaArchivo.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ public function getOntologiesToProcess(): array

// info page + title/name of ontology
preg_match('/<td>\s*\n*<a href="(\/info\?o=.*?)">(.*?)</sim', $ontologyEntryHtml, $data);

/** @var array<mixed> */
$data = $data;

if (isset($data[1]) && false === isEmpty($data[1])) {
$newEntry->setSourcePage('https://archivo.dbpedia.org'.$data[1]);
}
Expand Down Expand Up @@ -138,6 +142,9 @@ public function getOntologiesToProcess(): array

// latest update date
preg_match('/nt<\/a>.*?>([0-9]{4})\.([0-9]{2})\.([0-9]{2})/sim', $ontologyEntryHtml, $latest);
/** @var array<mixed> */
$latest = $latest;

if (isset($latest[1]) && false === isEmpty($latest[1])) {
$modified = $latest[1].'-'.$latest[2].'-'.$latest[3];
$newEntry->setModified($modified);
Expand Down
2 changes: 1 addition & 1 deletion scripts/src/Extractor/OntologyLookupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function run(): void
// load to terms data with further information
try {
$terms = $this->cache->sendCachedRequest($ontology['_links']['terms']['href'], $this->namespace);
} catch(Throwable $th) {
} catch (Throwable $th) {
if (str_contains($th->getMessage(), 'CURL error: HTTP/1.1 500')) {
echo PHP_EOL.$th->getMessage();
continue;
Expand Down

0 comments on commit b0bc3fd

Please sign in to comment.