Skip to content

Commit

Permalink
Removed unneeded local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
LucWollants committed Sep 11, 2024
1 parent 20a989b commit 2b05ae7
Show file tree
Hide file tree
Showing 27 changed files with 46 additions and 127 deletions.
38 changes: 10 additions & 28 deletions src/BackwardsCompatiblePayloadSerializerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ function (array $serializedObject) {
function (array $serializedObject) {
$serializedObject['class'] = TitleTranslated::class;

$serializedObject = self::replaceEventIdWithItemId($serializedObject);

return $serializedObject;
return self::replaceEventIdWithItemId($serializedObject);
}
);

Expand All @@ -114,9 +112,7 @@ function (array $serializedObject) {
function (array $serializedObject) {
$serializedObject['class'] = DescriptionTranslated::class;

$serializedObject = self::replaceEventIdWithItemId($serializedObject);

return $serializedObject;
return self::replaceEventIdWithItemId($serializedObject);
}
);

Expand Down Expand Up @@ -171,9 +167,7 @@ function (array $serializedObject) use ($labelRepository) {
function (array $serializedObject) {
$serializedObject['class'] = LabelAdded::class;

$serializedObject = self::replaceEventIdWithItemId($serializedObject);

return $serializedObject;
return self::replaceEventIdWithItemId($serializedObject);
}
);

Expand All @@ -184,9 +178,7 @@ function (array $serializedObject) {

$serializedObject = self::replaceEventIdWithItemId($serializedObject);

$serializedObject = self::replaceKeywordWithLabel($serializedObject);

return $serializedObject;
return self::replaceKeywordWithLabel($serializedObject);
}
);

Expand All @@ -197,9 +189,7 @@ function (array $serializedObject) {

$serializedObject = self::replaceEventIdWithItemId($serializedObject);

$serializedObject = self::replaceKeywordWithLabel($serializedObject);

return $serializedObject;
return self::replaceKeywordWithLabel($serializedObject);
}
);

Expand All @@ -208,9 +198,7 @@ function (array $serializedObject) {
function (array $serializedObject) {
$serializedObject['class'] = LabelRemoved::class;

$serializedObject = self::replaceEventIdWithItemId($serializedObject);

return $serializedObject;
return self::replaceEventIdWithItemId($serializedObject);
}
);

Expand All @@ -233,9 +221,7 @@ function (array $serializedObject) {
$payloadManipulatingSerializer->manipulateEventsOfClass(
'CultuurNet\UDB3\Place\Events\FacilitiesUpdated',
function (array $serializedObject) {
$serializedObject = self::replacePlaceIdWithItemId($serializedObject);

return $serializedObject;
return self::replacePlaceIdWithItemId($serializedObject);
}
);

Expand All @@ -245,9 +231,7 @@ function (array $serializedObject) {
$payloadManipulatingSerializer->manipulateEventsOfClass(
'CultuurNet\UDB3\Place\Events\GeoCoordinatesUpdated',
function (array $serializedObject) {
$serializedObject = self::replacePlaceIdWithItemId($serializedObject);

return $serializedObject;
return self::replacePlaceIdWithItemId($serializedObject);
}
);

Expand Down Expand Up @@ -355,8 +339,7 @@ function (array $serializedObject) {
$payloadManipulatingSerializer->manipulateEventsOfClass(
$refactoredEventEvent,
function (array $serializedObject) {
$serializedObject = self::replaceEventIdWithItemId($serializedObject);
return $serializedObject;
return self::replaceEventIdWithItemId($serializedObject);
}
);
}
Expand All @@ -378,8 +361,7 @@ function (array $serializedObject) {
$payloadManipulatingSerializer->manipulateEventsOfClass(
$refactoredPlaceEvent,
function (array $serializedObject) {
$serializedObject = self::replacePlaceIdWithItemId($serializedObject);
return $serializedObject;
return self::replacePlaceIdWithItemId($serializedObject);
}
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Calendar/CalendarConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,9 @@ private function formatDateTimeAsCdbTime(DateTimeInterface $timestamp, ?int $ind
throw new InvalidArgumentException('The CDB time index should not be higher than 59!');
}

$time = is_int($index)
return is_int($index)
? $timestamp->format('H:i') . ':' . str_pad((string) $index, 2, '0', STR_PAD_LEFT)
: $timestamp->format('H:i:s');

return $time;
}

private function createIndexedTimeString(int $index): string
Expand Down
4 changes: 1 addition & 3 deletions src/CulturefeedSlugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ public function slug(string $string): string
'',
$string
);
$string = preg_replace(
return preg_replace(
'/^' . preg_quote($this->separator) . '/',
'',
$string
);

return $string;
}

private function transliterate(string $string): string
Expand Down
3 changes: 1 addition & 2 deletions src/Event/ReadModel/JSONLD/EventLDProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ protected function applyEventCopied(
unset($eventJsonLD->availableFrom);

$newDocument = new JsonDocument($eventCopied->getItemId());
$newDocument = $newDocument->withBody($eventJsonLD);
return $newDocument;
return $newDocument->withBody($eventJsonLD);
}

protected function applyEventDeleted(EventDeleted $eventDeleted): JsonDocument
Expand Down
4 changes: 1 addition & 3 deletions src/EventExport/PriceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public function format($price): string

// Trim the decimal point if there were only zeroes after the decimal point. Don't do this in the same trim as
// above, as that would format 50,00 as 5.
$price = trim($price, $this->decimalPoint);

return $price;
return trim($price, $this->decimalPoint);
}

public function setSignificantDecimals(int $significantDecimals): void
Expand Down
4 changes: 1 addition & 3 deletions src/Http/Auth/CorsHeadersResponseDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public function decorate(ServerRequestInterface $request, ResponseInterface $res
// If specific headers have been requested to be used, echo them back. Otherwise allow the default headers.
$requestedHeaders = $request->getHeader('Access-Control-Request-Headers');
$allowedHeaders = count($requestedHeaders) ? $requestedHeaders[0] : 'authorization,x-api-key';
$response = $response->withHeader('Access-Control-Allow-Headers', $allowedHeaders);

return $response;
return $response->withHeader('Access-Control-Allow-Headers', $allowedHeaders);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ public function deserialize(string $data): BookingInfo
$availabilityEnds = DateTimeFactory::fromISO8601($bookingInfo['availabilityEnds']);
}

$bookingInfo = new BookingInfo(
return new BookingInfo(
isset($bookingInfo['url']) ? (string) $bookingInfo['url'] : null,
isset($bookingInfo['urlLabel']) ? MultilingualString::deserialize($bookingInfo['urlLabel']) : null,
isset($bookingInfo['phone']) ? (string) $bookingInfo['phone'] : null,
isset($bookingInfo['email']) ? (string) $bookingInfo['email'] : null,
$availabilityStarts,
$availabilityEnds
);

return $bookingInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private function removeNullPropertiesFromObject(stdClass $data): stdClass
private function removeNullValuesFromArray(array $data): array
{
$data = array_filter($data, fn ($value) => $value !== null);
$data = array_map(
return array_map(
function ($value) {
if ($value instanceof stdClass) {
return $this->removeNullPropertiesFromObject($value);
Expand All @@ -60,6 +60,5 @@ function ($value) {
},
$data
);
return $data;
}
}
4 changes: 1 addition & 3 deletions src/Model/Serializer/Offer/OfferDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ protected function denormalizeOffer(array $data): ImmutableOffer
$offer = $this->denormalizeMediaObjectReferences($data, $offer);
$offer = $this->denormalizeVideos($data, $offer);
$offer = $this->denormalizeWorkflowStatus($data, $offer);
$offer = $this->denormalizeAvailableFrom($data, $offer);

return $offer;
return $this->denormalizeAvailableFrom($data, $offer);
}

protected function denormalizeDescription(array $data, ImmutableOffer $offer): ImmutableOffer
Expand Down
4 changes: 1 addition & 3 deletions src/Offer/ReadModel/JSONLD/CdbXmlContactInfoImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ function (\CultureFeed_Cdb_Data_Url $url) {

private function dateFromUdb2UnixTime(int $unixTime): \DateTime
{
$dateTime = new \DateTime(
return new \DateTime(
'@' . $unixTime,
new \DateTimeZone('Europe/Brussels')
);

return $dateTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private function embedRelatedResource(
string $property,
DocumentRepository $documentRepository
): JsonDocument {
$document = $document->applyAssoc(
return $document->applyAssoc(
function (array $json) use ($property, $documentRepository): array {
$url = $json[$property]['@id'] ?? null;
if (!is_string($url)) {
Expand All @@ -73,8 +73,6 @@ function (array $json) use ($property, $documentRepository): array {
return $json;
}
);

return $document;
}

private function getUuidFromUrl(string $url): string
Expand Down
4 changes: 1 addition & 3 deletions src/Offer/ReadModel/JSONLD/OfferUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OfferUpdate
*/
public static function calendar(Calendar $calendar): \Closure
{
$offerCalenderUpdate = function ($body) use ($calendar) {
return function ($body) use ($calendar) {
// Purge any existing calendar data
unset(
$body->calendarType,
Expand All @@ -37,7 +37,5 @@ public static function calendar(Calendar $calendar): \Closure
$calendar->toJsonLd()
);
};

return $offerCalenderUpdate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ private function removeObsoleteProperties(JsonDocument $jsonDocument): JsonDocum

return $jsonDocument->applyAssoc(
function (array $json) use ($obsoleteProperties) {
$json = array_diff_key($json, array_flip($obsoleteProperties));
return $json;
return array_diff_key($json, array_flip($obsoleteProperties));
}
);
}
Expand All @@ -237,9 +236,7 @@ function (array $json) {
};

$json = $filterNullLabels($json, 'labels');
$json = $filterNullLabels($json, 'hiddenLabels');

return $json;
return $filterNullLabels($json, 'hiddenLabels');
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(DocumentRepository $repository, TermRepository $term
public function fetch(string $id, bool $includeMetadata = false): JsonDocument
{
$document = parent::fetch($id, $includeMetadata);
$document = $document->applyAssoc(
return $document->applyAssoc(
function (array $json) {
if (!isset($json['terms']) || !is_array($json['terms'])) {
// JSON is not formatted as expected, continue without trying to fix it.
Expand Down Expand Up @@ -60,6 +60,5 @@ function ($term) {
return $json;
}
);
return $document;
}
}
10 changes: 3 additions & 7 deletions src/Organizer/ReadModel/JSONLD/PropertyPolyfillRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ public function fetch(string $id, bool $includeMetadata = false): JsonDocument
$document = parent::fetch($id, $includeMetadata);
$document = $this->polyfillNewProperties($document);
$document = $this->removeNullLabels($document);
$document = $this->fixDuplicateLabelVisibility($document);
return $document;
return $this->fixDuplicateLabelVisibility($document);
}

private function polyfillNewProperties(JsonDocument $jsonDocument): JsonDocument
{
return $jsonDocument->applyAssoc(
function (array $json) {
$json = $this->polyfillImageType($json);
$json = $this->polyfillImageInLanguage($json);
return $json;
return $this->polyfillImageInLanguage($json);
}
);
}
Expand Down Expand Up @@ -97,9 +95,7 @@ function (array $json) {
};

$json = $filterNullLabels($json, 'labels');
$json = $filterNullLabels($json, 'hiddenLabels');

return $json;
return $filterNullLabels($json, 'hiddenLabels');
}
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Role/ReadModel/Labels/LabelRolesProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ private function getRoleDetails(JsonDocument $document): array

private function createNewDocument(UUID $uuid): JsonDocument
{
$document = new JsonDocument(
return new JsonDocument(
$uuid->toString(),
Json::encode([])
);
return $document;
}
}
3 changes: 1 addition & 2 deletions src/Role/ReadModel/Labels/RoleLabelsProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ private function getLabelDetails(JsonDocument $document): array

private function createNewDocument(UUID $uuid): JsonDocument
{
$document = new JsonDocument(
return new JsonDocument(
$uuid->toString(),
Json::encode([])
);
return $document;
}
}
4 changes: 1 addition & 3 deletions src/StringFilter/StripHtmlStringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public function filter(string $string): string
$string = $this->limitConsecutiveNewlines($string, 2);

// Trim any whitespace or newlines from the start and/or end of the string.
$string = trim($string);

return $string;
return trim($string);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/Event/CdbXMLEventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ private function eventFromFile(string $fileName, string $eventClass)
{
$cdbXml = SampleFiles::read($this->samplesPath . '/' . $fileName);

$event = new $eventClass(
return new $eventClass(
self::AN_EVENT_ID,
$cdbXml,
'http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.2/FINAL'
);

return $event;
}
}
Loading

0 comments on commit 2b05ae7

Please sign in to comment.