Failed Conditions
Push — master ( e0fde8...98a030 )
by
unknown
44:34 queued 15:21
created

QuoteStorageStrategyProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A provideStorage() 0 13 3
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerFeature\Client\SelfServicePortal\Asset\Quote;
9
10
use Spryker\Client\Quote\QuoteClientInterface;
11
use SprykerFeature\Shared\SelfServicePortal\Exception\QuoteStorageStrategyNotFound;
12
13
class QuoteStorageStrategyProvider implements QuoteStorageStrategyProviderInterface
14
{
15
    /**
16
     * @param \Spryker\Client\Quote\QuoteClientInterface $quoteClient
17
     * @param array<\SprykerFeature\Client\SelfServicePortal\Asset\Quote\QuoteStorageStrategyInterface> $quoteStorageStrategies
18
     */
19
    public function __construct(
20
        protected QuoteClientInterface $quoteClient,
21
        protected array $quoteStorageStrategies
22
    ) {
23
    }
24
25
    public function provideStorage(): QuoteStorageStrategyInterface
26
    {
27
        $storageStrategyType = $this->quoteClient->getStorageStrategy();
28
        foreach ($this->quoteStorageStrategies as $storageStrategy) {
29
            if ($storageStrategy->getStorageStrategy() === $storageStrategyType) {
30
                return $storageStrategy;
31
            }
32
        }
33
34
        throw new QuoteStorageStrategyNotFound(
35
            sprintf(
36
                'There is no quote storage strategy with name: %s. ',
37
                $storageStrategyType,
38
            ),
39
        );
40
    }
41
}
42