Skip to content

Commit

Permalink
let exception bubbling (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
qdequippe authored Feb 12, 2024
1 parent d412718 commit 9e327d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
13 changes: 5 additions & 8 deletions src/MeetupCom/Meetup/MeetupComMeetupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Fop\Meetup\ValueObject\Meetup;
use Fop\Utils\CityNormalizer;
use Location\Coordinate;
use Throwable;

final readonly class MeetupComMeetupFactory
{
Expand Down Expand Up @@ -45,11 +44,7 @@ public function createFromData(array $data): ?Meetup
return null;
}

try {
$location = $this->createLocation($data);
} catch (Throwable) {
return null;
}
$location = $this->createLocation($data);

$name = $this->createName($data);

Expand Down Expand Up @@ -83,7 +78,7 @@ private function shouldSkipMeetup(array $meetup): bool
}

// no location with address
if (! isset($meetup['location']['address'])) {
if (! isset($meetup['location']['address']['streetAddress'])) {
return true;
}

Expand All @@ -101,7 +96,9 @@ private function createLocation(array $data): Location
$venue[self::CITY] = $this->cityNormalizer->normalize($city);

if (! isset($data['location']['geo']['latitude']) && ! isset($data['location']['geo']['longitude'])) {
$coordinate = $this->geocoder->retrieveCoordinate($data['location']['address']['streetAddress']);
$coordinate = $this->geocoder->retrieveCoordinate(
html_entity_decode((string) $data['location']['address']['streetAddress'])
);
} else {
$coordinate = new Coordinate($data['location']['geo']['latitude'], $data['location']['geo']['longitude']);
}
Expand Down
16 changes: 8 additions & 8 deletions src/MeetupCom/MeetupComMeetupImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ public function import(SymfonyStyle $symfonyStyle): array
$errors = [];
$meetups = [];

foreach ($this->groupRepository->fetchAll() as $group) {
$groups = $this->groupRepository->fetchAll();
$progressBar = $symfonyStyle->createProgressBar();

foreach ($progressBar->iterate($groups) as $group) {
try {
$groupSlug = $group->getMeetupComSlug();

$message = sprintf('Scanning "%s" group', $groupSlug);
$symfonyStyle->writeln(' * ' . $message);

$meetupsData = $this->meetupComCrawler->getMeetupsByGroupSlug($groupSlug);

$note = sprintf('Found %d meetups', count($meetupsData));
$symfonyStyle->note($note);

if ($meetupsData === []) {
continue;
}

$groupMeetups = $this->createMeetupsFromMeetupsData($meetupsData);
$meetups = array_merge($meetups, $groupMeetups);

$meetups[] = $groupMeetups;
} catch (Exception $exception) {
$errors[] = $exception->getMessage();
}
}

$meetups = array_merge(...$meetups);

// report errors
foreach ($errors as $error) {
$symfonyStyle->error($error);
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/NominatimGeocoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function retrieveCoordinate(string $address): Coordinate
throw CoordinateNotFoundForAddressException::create($address);
}

return new Coordinate($placeFound['lat'], $placeFound['lon']);
return new Coordinate((float) $placeFound['lat'], (float) $placeFound['lon']);
}
}

0 comments on commit 9e327d1

Please sign in to comment.