Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @return value ?RetailerTimeSlotInterface and not array #131

Open
aurelien-andre opened this issue Jan 13, 2022 · 0 comments
Open

Fix @return value ?RetailerTimeSlotInterface and not array #131

aurelien-andre opened this issue Jan 13, 2022 · 0 comments

Comments

@aurelien-andre
Copy link

aurelien-andre commented Jan 13, 2022

* @return RetailerTimeSlotInterface[]

If a TimeSloteInterface is found, return that interface and not an array.

Change

/**
 * Retrieve opening hours for a given date
 *
 * @SuppressWarnings(PHPMD.StaticAccess)
 *
 * @param RetailerInterface $retailer The retailer
 * @param null              $dateTime The date to retrieve opening hours for
 *
 * @return RetailerTimeSlotInterface|null
 */
public function getOpeningHours($retailer, $dateTime = null): ?RetailerTimeSlotInterface
{
    $dayOpening = null;

    if ($dateTime == null) {
        $dateTime = new \DateTime();
    }
    if (is_string($dateTime)) {
        $dateTime = \DateTime::createFromFormat('Y-m-d', $dateTime);
    }

    $dayOfWeek = $dateTime->format('w');
    $date      = $dateTime->format('Y-m-d');

    $openingHours = $retailer->getExtensionAttributes()->getOpeningHours();
    $specialOpeningHours = $retailer->getExtensionAttributes()->getSpecialOpeningHours();

    if (isset($openingHours[$dayOfWeek])) {
        $dayOpening = $openingHours[$dayOfWeek];
    }

    if (isset($specialOpeningHours[$date])) {
        $dayOpening = $specialOpeningHours[$date];
    }

    return $dayOpening;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant