Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Read configuration.
$configArray = require $configPath;
$this->config = new Config($configArray);

return Command::SUCCESS;
}
}
52 changes: 26 additions & 26 deletions Command/GeoJSONCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private function extractDetailsFromWikidata($entity, array &$warnings = []): Det
* Extract details from CSV file.
*
* @param Element $object OpenStreetMap element (relation/way/node).
* @param array $warnings
* @param string[] $warnings
* @return null|Details
*/
private function extractDetailsFromCSV($object, array &$warnings = []): ?Details
Expand Down Expand Up @@ -331,22 +331,22 @@ private function getGenderFromConfig($object, array &$warnings = []): ?string
* @param string[] $warnings
* @return null|string
*/
private function getGenderFromEvent($object, array &$warnings = []): ?string
{
if (!isset($this->event) || count($this->event) === 0) {
return null;
}

if (isset($object->tags->{'name:fr'}, $this->event[md5($object->tags->{'name:fr'})])) { // @phpstan-ignore-line
return $this->event[md5($object->tags->{'name:fr'})]; // @phpstan-ignore-line
} elseif (isset($object->tags->{'name:nl'}, $this->event[md5($object->tags->{'name:nl'})])) { // @phpstan-ignore-line
return $this->event[md5($object->tags->{'name:nl'})]; // @phpstan-ignore-line
} elseif (isset($object->tags->{'name'}, $this->event[md5($object->tags->{'name'})])) { // @phpstan-ignore-line
return $this->event[md5($object->tags->{'name'})]; // @phpstan-ignore-line
}

return null;
}
// private function getGenderFromEvent($object, array &$warnings = []): ?string
// {
// if (!isset($this->event) || count($this->event) === 0) {
// return null;
// }

// if (isset($object->tags->{'name:fr'}, $this->event[md5($object->tags->{'name:fr'})])) {
// return $this->event[md5($object->tags->{'name:fr'})];
// } elseif (isset($object->tags->{'name:nl'}, $this->event[md5($object->tags->{'name:nl'})])) {
// return $this->event[md5($object->tags->{'name:nl'})];
// } elseif (isset($object->tags->{'name'}, $this->event[md5($object->tags->{'name'})])) {
// return $this->event[md5($object->tags->{'name'})];
// }

// return null;
// }

/**
* Create GeoJSON feature "property".
Expand All @@ -361,15 +361,15 @@ private function getGenderFromEvent($object, array &$warnings = []): ?string
private function createProperties($object, array &$warnings = []): Properties
{
$properties = new Properties();
$properties->name = $object->tags->name ?? null; // @phpstan-ignore-line
$properties->wikidata = $object->tags->wikidata ?? null; // @phpstan-ignore-line
$properties->name = $object->tags->name ?? null; // @phpstan-ignore property.notFound
$properties->wikidata = $object->tags->wikidata ?? null; // @phpstan-ignore property.notFound
$properties->source = null;
$properties->gender = null;
$properties->details = null;

// Try to extract information from `name:etymology:wikidata` tag in OpenStreetMap
if (isset($object->tags->{'name:etymology:wikidata'})) { // @phpstan-ignore-line
$idsEtymology = explode(';', $object->tags->{'name:etymology:wikidata'}); // @phpstan-ignore-line
if (isset($object->tags->{'name:etymology:wikidata'})) { // @phpstan-ignore property.notFound,property.dynamicName
$idsEtymology = explode(';', $object->tags->{'name:etymology:wikidata'}); // @phpstan-ignore property.dynamicName
$idsEtymology = array_map('trim', $idsEtymology);

$detailsEtymology = [];
Expand Down Expand Up @@ -403,7 +403,7 @@ private function createProperties($object, array &$warnings = []): Properties
}

// Try to extract information from `P138` (NamedAfter) property in Wikidata
if (isset($object->tags->wikidata)) {
if (isset($object->tags->wikidata)) { // @phpstan-ignore property.notFound
if (preg_match('/^Q[0-9]+$/', $object->tags->wikidata) !== 1) {
$warnings[] = sprintf('Format of `wikidata` is invalid (%s) for %s(%d).', $object->tags->wikidata, $object->type, $object->id);
} else {
Expand Down Expand Up @@ -475,12 +475,12 @@ private function createProperties($object, array &$warnings = []): Properties
if (isset($genderEtymology, $detailsEtymology)) {
// If `name:etymology:wikidata` tag is set, use it to extract details and determine gender.
$properties->source = 'wikidata';
$properties->gender = $genderEtymology ? $genderEtymology : null;
$properties->gender = $genderEtymology;
Comment thread
jbelien marked this conversation as resolved.
Outdated
$properties->details = $detailsEtymology;
} elseif (isset($genderWikidata, $detailsWikidata)) {
// If `P138` (NamedAfter) property is set, use it to extract details and determine gender.
$properties->source = 'wikidata';
$properties->gender = $genderWikidata ? $genderWikidata : null;
$properties->gender = $genderWikidata;
Comment thread
jbelien marked this conversation as resolved.
Outdated
$properties->details = $detailsWikidata;
} elseif (!is_null($details = $this->extractDetailsFromCSV($object, $warnings))) {
// If relation/way is defined in CSV file, use it to extract details and determine gender.
Expand Down Expand Up @@ -518,7 +518,7 @@ private static function createGeometry($object, array $relations, array $ways, a
/** @var Relation */ $object = $object;
/** @var Member[] */ $members = [];

switch ($object->tags->type) {
switch ($object->tags->type) { // @phpstan-ignore property.nonObject
case 'associatedStreet':
case 'street':
$members = array_filter(
Expand Down Expand Up @@ -554,7 +554,7 @@ function ($member): bool {
}
break;
default:
$warnings[] = sprintf('<warning>Type "%s" is not supported (yet) for relation(%d).</warning>', $object->tags->type, $object->id);
$warnings[] = sprintf('<warning>Type "%s" is not supported (yet) for relation(%d).</warning>', $object->tags->type, $object->id); // @phpstan-ignore property.nonObject
break;
}

Expand Down
6 changes: 3 additions & 3 deletions Command/WikidataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
array_merge($overpassR->elements ?? [], $overpassW->elements ?? []),
function ($element): bool {
return isset($element->tags) &&
(isset($element->tags->wikidata) || isset($element->tags->{'name:etymology:wikidata'})); // @phpstan-ignore-line
(isset($element->tags->wikidata) || isset($element->tags->{'name:etymology:wikidata'})); // @phpstan-ignore property.notFound,property.notFound,property.dynamicName
}
);

Expand All @@ -98,9 +98,9 @@ function ($element): bool {

foreach ($elements as $element) {
/** @var string|null */
$wikidataTag = $element->tags->wikidata ?? null; // @phpstan-ignore-line
$wikidataTag = $element->tags->wikidata ?? null; // @phpstan-ignore property.notFound
/** @var string|null */
$etymologyTag = $element->tags->{'name:etymology:wikidata'} ?? null; // @phpstan-ignore-line
$etymologyTag = $element->tags->{'name:etymology:wikidata'} ?? null; // @phpstan-ignore property.notFound,property.dynamicName

// Download Wikidata item(s) defined in `name:etymology:wikidata` tag
if (!is_null($etymologyTag) && $etymologyTag !== $wikidataTag) {
Expand Down
26 changes: 13 additions & 13 deletions Wikidata/Wikidata.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function extractLabels($entity, array $languages): array
$labels = [];

foreach ($languages as $language) {
$label = $entity->labels->{$language} ?? $entity->labels->mul ?? null; // @phpstan-ignore-line
$label = $entity->labels->{$language} ?? $entity->labels->mul ?? null; // @phpstan-ignore property.notFound,property.dynamicName
if ($label !== null) {
$labels[$language] = $label;
}
Expand All @@ -62,8 +62,8 @@ public static function extractDescriptions($entity, array $languages): array
$descriptions = [];

foreach ($languages as $language) {
if (isset($entity->descriptions->{$language})) { // @phpstan-ignore-line
$descriptions[$language] = $entity->descriptions->{$language}; // @phpstan-ignore-line
if (isset($entity->descriptions->{$language})) { // @phpstan-ignore property.dynamicName
$descriptions[$language] = $entity->descriptions->{$language}; // @phpstan-ignore property.dynamicName
}
}

Expand All @@ -81,8 +81,8 @@ public static function extractSitelinks($entity, array $languages): array
$sitelinks = [];

foreach ($languages as $language) {
if (isset($entity->sitelinks->{$language . 'wiki'})) { // @phpstan-ignore-line
$sitelinks[$language . 'wiki'] = $entity->sitelinks->{$language . 'wiki'}; // @phpstan-ignore-line
if (isset($entity->sitelinks->{$language . 'wiki'})) { // @phpstan-ignore property.dynamicName
$sitelinks[$language . 'wiki'] = $entity->sitelinks->{$language . 'wiki'}; // @phpstan-ignore property.dynamicName
}
}

Expand All @@ -103,7 +103,7 @@ public static function extractNicknames($entity, array $languages): ?array

foreach ($claims as $value) {
/** @var \stdClass */
$mainValue = $value->mainsnak->datavalue->value; // @phpstan-ignore-line
$mainValue = $value->mainsnak->datavalue->value; // @phpstan-ignore property.notFound
$language = $mainValue->language;

if (in_array($language, $languages, true)) {
Expand All @@ -127,13 +127,13 @@ public static function extractNamedAfter($entity): ?array
$claims = $entity->claims->P138 ?? [];

foreach ($claims as $value) {
$endTime = $value->qualifiers->P582[0]->datavalue->value->time ?? null; // @phpstan-ignore-line
$endTime = $value->qualifiers->P582[0]->datavalue->value->time ?? null; // @phpstan-ignore property.notFound
if (!is_null($endTime) && $endTime < date('c')) {
continue;
}

/** @var string */
$id = $value->mainsnak->datavalue->value->id; // @phpstan-ignore-line
$id = $value->mainsnak->datavalue->value->id; // @phpstan-ignore property.notFound

$identifiers[] = $id;
}
Expand All @@ -146,31 +146,31 @@ public static function extractNamedAfter($entity): ?array
*/
public static function extractDateOfBirth($entity): ?string
{
return isset($entity->claims->P569) ? $entity->claims->P569[0]->mainsnak->datavalue->value->time ?? null : null; // @phpstan-ignore-line
return isset($entity->claims->P569) ? $entity->claims->P569[0]->mainsnak->datavalue->value->time ?? null : null; // @phpstan-ignore property.notFound
}

/**
* @param Entity $entity
*/
public static function extractDateOfDeath($entity): ?string
{
return isset($entity->claims->P570) ? $entity->claims->P570[0]->mainsnak->datavalue->value->time ?? null : null; // @phpstan-ignore-line
return isset($entity->claims->P570) ? $entity->claims->P570[0]->mainsnak->datavalue->value->time ?? null : null; // @phpstan-ignore property.notFound
}

/**
* @param Entity $entity
*/
public static function extractImage($entity): ?string
{
return isset($entity->claims->P18) ? $entity->claims->P18[0]->mainsnak->datavalue->value ?? null : null; // @phpstan-ignore-line
return isset($entity->claims->P18) ? $entity->claims->P18[0]->mainsnak->datavalue->value ?? null : null; // @phpstan-ignore property.notFound
}

/**
* @param Entity $entity
*/
public static function extractGender($entity): ?string
{
$identifier = isset($entity->claims->P21) ? $entity->claims->P21[0]->mainsnak->datavalue->value->id ?? null : null; // @phpstan-ignore-line
$identifier = isset($entity->claims->P21) ? $entity->claims->P21[0]->mainsnak->datavalue->value->id ?? null : null; // @phpstan-ignore property.notFound

switch ($identifier) {
case 'Q6581097': // male
Expand Down Expand Up @@ -212,7 +212,7 @@ private static function extractInstances($entity): ?array
}

return array_map(function ($p) {
return $p->mainsnak->datavalue->value->id; // @phpstan-ignore-line
return $p->mainsnak->datavalue->value->id; // @phpstan-ignore property.notFound
}, $property);
}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"dragonmantank/cron-expression": "^3.1"
},
"require-dev": {
"phpstan/phpstan": "^0.12.83",
"phpstan/phpstan-strict-rules": "^0.12.9",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-strict-rules": "^2.0",
"squizlabs/php_codesniffer": "^4.0"
},
"autoload": {
Expand Down
Loading