PaymentMethodViewFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createList() 0 10 2
A createFromPaymentMethod() 0 9 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusVueStorefrontPlugin\Factory\Cart;
14
15
use BitBag\SyliusVueStorefrontPlugin\View\Cart\PaymentMethodView;
16
use Sylius\Component\Core\Model\PaymentMethodInterface as SyliusPaymentMethodInterface;
17
18
final class PaymentMethodViewFactory implements PaymentMethodViewFactoryInterface
19
{
20
    /** @var string */
21
    private $paymentMethodViewClass;
22
23
    public function __construct(string $paymentMethodViewClass)
24
    {
25
        $this->paymentMethodViewClass = $paymentMethodViewClass;
26
    }
27
28
    public function createList(array $syliusPaymentMethods): array
29
    {
30
        $paymentMethodsList = [];
31
32
        foreach ($syliusPaymentMethods as $syliusPaymentMethod) {
33
            $paymentMethodsList[] = $this->createFromPaymentMethod($syliusPaymentMethod);
34
        }
35
36
        return $paymentMethodsList;
37
    }
38
39
    private function createFromPaymentMethod(SyliusPaymentMethodInterface $syliusPaymentMethod): PaymentMethodView
40
    {
41
        /** @var PaymentMethodView $paymentMethodView */
42
        $paymentMethodView = new $this->paymentMethodViewClass();
43
        $paymentMethodView->code = $syliusPaymentMethod->getCode();
44
        $paymentMethodView->title = $syliusPaymentMethod->getName();
45
46
        return $paymentMethodView;
47
    }
48
}
49