AddressExampleFactory::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 11
rs 10
c 1
b 0
f 0
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