Skip to content

Commit

Permalink
Coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
jeppekroghitk committed Nov 12, 2024
1 parent a77e2aa commit cab2f20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
24 changes: 11 additions & 13 deletions src/Feed/EventDatabaseApiFeedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ class EventDatabaseApiFeedType implements FeedTypeInterface
final public const int REQUEST_TIMEOUT = 10;

public function __construct(
private readonly FeedService $feedService,
private readonly HttpClientInterface $client,
private readonly LoggerInterface $logger,
private readonly FeedService $feedService,
private readonly HttpClientInterface $client,
private readonly LoggerInterface $logger,
private readonly EntityManagerInterface $entityManager,
)
{
}
) {}

/**
* @param Feed $feed
Expand Down Expand Up @@ -59,9 +57,9 @@ public function getData(Feed $feed): array

$queryParams = array_filter([
'items_per_page' => $numberOfItems,
'occurrences.place.id' => array_map(static fn($place) => str_replace('/api/places/', '', (string)$place['value']), $places),
'organizer.id' => array_map(static fn($organizer) => str_replace('/api/organizers/', '', (string)$organizer['value']), $organizers),
'tags' => array_map(static fn($tag) => str_replace('/api/tags/', '', (string)$tag['value']), $tags),
'occurrences.place.id' => array_map(static fn ($place) => str_replace('/api/places/', '', (string) $place['value']), $places),
'organizer.id' => array_map(static fn ($organizer) => str_replace('/api/organizers/', '', (string) $organizer['value']), $organizers),
'tags' => array_map(static fn ($tag) => str_replace('/api/tags/', '', (string) $tag['value']), $tags),
]);

$response = $this->client->request(
Expand Down Expand Up @@ -92,9 +90,9 @@ public function getData(Feed $feed): array
$content = $response->getContent();
$decoded = json_decode($content, null, 512, JSON_THROW_ON_ERROR);

$baseUrl = parse_url((string)$decoded->event->{'url'}, PHP_URL_HOST);
$baseUrl = parse_url((string) $decoded->event->{'url'}, PHP_URL_HOST);

$eventOccurrence = (object)[
$eventOccurrence = (object) [
'eventId' => $decoded->event->{'@id'},
'occurrenceId' => $decoded->{'@id'},
'ticketPurchaseUrl' => $decoded->event->{'ticketPurchaseUrl'},
Expand All @@ -110,7 +108,7 @@ public function getData(Feed $feed): array
];

if (isset($decoded->place)) {
$eventOccurrence->place = (object)[
$eventOccurrence->place = (object) [
'name' => $decoded->place->name,
'streetAddress' => $decoded->place->streetAddress,
'addressLocality' => $decoded->place->addressLocality,
Expand Down Expand Up @@ -257,7 +255,7 @@ public function getConfigOptions(Request $request, FeedSource $feedSource, strin
foreach ($members as $member) {
// Special handling of searching in tags, since EventDatabaseApi does not support this.
if ('tags' == $type) {
if (!isset($queryParams['name']) || str_contains(strtolower((string)$member->name), strtolower((string)$queryParams['name']))) {
if (!isset($queryParams['name']) || str_contains(strtolower((string) $member->name), strtolower((string) $queryParams['name']))) {
$result[] = $displayAsOptions ? [
'label' => $member->name,
'value' => $member->{'@id'},
Expand Down
5 changes: 2 additions & 3 deletions src/State/FeedSourceProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct(
parent::__construct($entityManager, $persistProcessor, $removeProcessor);
}


public function process($data, Operation $operation, array $uriVariables = [], array $context = []): void
{
if ($operation instanceof DeleteOperationInterface) {

Check failure on line 38 in src/State/FeedSourceProcessor.php

View workflow job for this annotation

GitHub Actions / Psalm (PHP 8.3)

UndefinedClass

src/State/FeedSourceProcessor.php:38:35: UndefinedClass: Class, interface or enum named App\State\DeleteOperationInterface does not exist (see https://psalm.dev/019)
Expand Down Expand Up @@ -113,7 +112,7 @@ private function validateFeedSource(object $object, Operation $operation): void
$this->executeValidation($secrets, $validator, $feedTypeValidationSchema);
}

private function prepareValidator(): validator
private function prepareValidator(): Validator
{
$schemaStorage = new SchemaStorage();
$feedSourceValidationSchema = (new FeedSource())->getSchema();
Expand All @@ -125,7 +124,7 @@ private function prepareValidator(): validator
private function executeValidation($object, $validator, $schema = null): void
{
$validator->validate($object, $schema ?? (new FeedSource())->getSchema());
if (! $validator->isValid()) {
if (!$validator->isValid()) {
throw new InvalidArgumentException($this->getErrorMessage($validator));
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Api/FeedSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public function testCreateFeedSourceWithoutTitle(): void
],
]);
$this->assertMatchesRegularExpression('@^/v\d/[\w-]+/([A-Za-z0-9]{26})$@', $response->toArray()['@id']);

}

public function testCreateFeedSourceWithoutDescription(): void
Expand Down Expand Up @@ -199,7 +198,7 @@ public function testCreateFeedSourceWithEventDatabaseFeedTypeWithRequiredSecret(
],
]);

//$this->assertResponseIsSuccessful();
// $this->assertResponseIsSuccessful();
$this->assertMatchesRegularExpression('@^/v\d/[\w-]+/([A-Za-z0-9]{26})$@', $response->toArray()['@id']);
}

Expand Down

0 comments on commit cab2f20

Please sign in to comment.