Issues (3641)

...rServicePointAvailabilityResponseItemSorter.php (1 issue)

1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace Spryker\Client\ClickAndCollectExample\Sorter;
9
10
use Generated\Shared\Transfer\ProductOfferServicePointAvailabilityResponseItemTransfer;
11
12
class ProductOfferServicePointAvailabilityResponseItemSorter implements ProductOfferServicePointAvailabilityResponseItemSorterInterface
13
{
14
    /**
15
     * @param list<\Generated\Shared\Transfer\ProductOfferServicePointAvailabilityResponseItemTransfer> $productOfferServicePointAvailabilityResponseItemTransfers
16
     * @param list<string> $requestedProductOfferReferences
17
     *
18
     * @return list<\Generated\Shared\Transfer\ProductOfferServicePointAvailabilityResponseItemTransfer>
19
     */
20
    public function sortProductOfferServicePointAvailabilityResponseItemTransfersByRequestedProductOffers(
21
        array $productOfferServicePointAvailabilityResponseItemTransfers,
22
        array $requestedProductOfferReferences
23
    ): array {
24
        $prioritizedProductOfferServicePointAvailabilityResponseItemTransfers = [];
25
        $regularProductOfferServicePointAvailabilityResponseItemTransfers = [];
26
27
        foreach ($productOfferServicePointAvailabilityResponseItemTransfers as $productOfferServicePointAvailabilityResponseItemTransfer) {
28
            if ($this->isPrioritizedProductOfferServicePointAvailabilityResponseItemTransfer($productOfferServicePointAvailabilityResponseItemTransfer, $requestedProductOfferReferences)) {
29
                $prioritizedProductOfferServicePointAvailabilityResponseItemTransfers[] = $productOfferServicePointAvailabilityResponseItemTransfer;
30
31
                continue;
32
            }
33
34
            $regularProductOfferServicePointAvailabilityResponseItemTransfers[] = $productOfferServicePointAvailabilityResponseItemTransfer;
35
        }
36
37
        return array_merge(
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_merge($prio...yResponseItemTransfers) returns the type array which is incompatible with the documented return type Spryker\Client\ClickAndCollectExample\Sorter\list.
Loading history...
38
            $prioritizedProductOfferServicePointAvailabilityResponseItemTransfers,
39
            $regularProductOfferServicePointAvailabilityResponseItemTransfers,
40
        );
41
    }
42
43
    /**
44
     * @param \Generated\Shared\Transfer\ProductOfferServicePointAvailabilityResponseItemTransfer $productOfferServicePointAvailabilityResponseItemTransfer
45
     * @param list<string> $requestedProductOfferReferences
46
     *
47
     * @return bool
48
     */
49
    protected function isPrioritizedProductOfferServicePointAvailabilityResponseItemTransfer(
50
        ProductOfferServicePointAvailabilityResponseItemTransfer $productOfferServicePointAvailabilityResponseItemTransfer,
51
        array $requestedProductOfferReferences
52
    ): bool {
53
        $productOfferReference = $productOfferServicePointAvailabilityResponseItemTransfer->getProductOfferReference();
54
55
        if (!$productOfferReference) {
56
            return false;
57
        }
58
59
        return in_array($productOfferReference, $requestedProductOfferReferences, true);
60
    }
61
}
62