Completed
Push — master ( eee865...6f8c44 )
by Rafał
08:46
created

BankAccountFormFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createBankAccountForm() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Bundle\PayumBundle\Factory;
6
7
use PH\Bundle\PayumBundle\Form\Type\BankAccountType;
8
use PH\Bundle\PayumBundle\Form\Type\RecurringBankAccountType;
9
use PH\Component\Core\Model\SubscriptionInterface;
10
use Symfony\Component\Form\FormFactoryInterface;
11
use Symfony\Component\Form\FormInterface;
12
13
final class BankAccountFormFactory implements BankAccountFormFactoryInterface
14
{
15
    /**
16
     * @var FormFactoryInterface
17
     */
18
    private $formFactory;
19
20
    /**
21
     * BankAccountFormFactory constructor.
22
     *
23
     * @param FormFactoryInterface $formFactory
24
     */
25
    public function __construct(FormFactoryInterface $formFactory)
26
    {
27
        $this->formFactory = $formFactory;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function createBankAccountForm(string $type): FormInterface
34
    {
35
        switch ($type) {
36
            case SubscriptionInterface::TYPE_RECURRING:
37
                return $this->formFactory->create(RecurringBankAccountType::class);
38
            case SubscriptionInterface::TYPE_NON_RECURRING:
39
                return $this->formFactory->create(BankAccountType::class);
40
            default:
41
                throw new \InvalidArgumentException(sprintf('%s is not a valid subscription type', $type));
42
        }
43
    }
44
}
45