AddressExampleFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 32
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 11 1
A create() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewebe\SyliusVATPlugin\Fixture\Factory;
6
7
use Gewebe\SyliusVATPlugin\Entity\VatNumberAddressInterface;
8
use Sylius\Bundle\CoreBundle\Fixture\Factory\AddressExampleFactory as BaseAddressExampleFactory;
9
use Sylius\Component\Core\Model\AddressInterface;
10
use Symfony\Component\OptionsResolver\OptionsResolver;
11
12
final class AddressExampleFactory extends BaseAddressExampleFactory
13
{
14
    public function create(array $options = []): AddressInterface
15
    {
16
        $address = parent::create($options);
17
18
        if (!$address instanceof VatNumberAddressInterface) {
19
            return $address;
20
        }
21
22
        if (isset($options['vat_number'])) {
23
            $address->setVatNumber((string) $options['vat_number']);
24
        }
25
26
        if (isset($options['vat_valid'])) {
27
            $address->setVatValid((bool) $options['vat_valid']);
28
        }
29
30
        return $address;
31
    }
32
33
    protected function configureOptions(OptionsResolver $resolver): void
34
    {
35
        parent::configureOptions($resolver);
36
37
        $resolver
38
            ->setDefault('vat_number', null)
39
            ->setAllowedTypes('vat_number', ['null', 'string'])
40
            ->setDefault('vat_valid', false)
41
            ->setAllowedTypes('vat_valid', 'bool')
42
            ->setDefault('vat_validated_at', null)
43
            ->setAllowedTypes('vat_validated_at', ['null', 'string'])
44
        ;
45
    }
46
}
47