AddressExampleFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 18
dl 0
loc 34
rs 10
c 2
b 1
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 11 1
A create() 0 19 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
        $options = $this->optionsResolver->resolve($options);
17
18
        $address = parent::create($options);
19
20
        if (!$address instanceof VatNumberAddressInterface) {
21
            return $address;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $address returns the type Sylius\Component\Core\Model\AddressInterface which is incompatible with the return type mandated by Sylius\Bundle\CoreBundle...toryInterface::create() of Sylius\Bundle\CoreBundle\Fixture\Factory\T.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
22
        }
23
24
        if (isset($options['vat_number'])) {
25
            $address->setVatNumber($options['vat_number']);
26
        }
27
28
        if (isset($options['vat_valid'])) {
29
            $address->setVatValid($options['vat_valid']);
30
        }
31
32
        return $address;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $address returns the type Gewebe\SyliusVATPlugin\E...tNumberAddressInterface which is incompatible with the return type mandated by Sylius\Bundle\CoreBundle...toryInterface::create() of Sylius\Bundle\CoreBundle\Fixture\Factory\T.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
33
    }
34
35
    protected function configureOptions(OptionsResolver $resolver): void
36
    {
37
        parent::configureOptions($resolver);
38
39
        $resolver
40
            ->setDefault('vat_number', null)
41
            ->setAllowedTypes('vat_number', ['null', 'string'])
42
            ->setDefault('vat_valid', null)
43
            ->setAllowedTypes('vat_valid', ['null', 'bool'])
44
            ->setDefault('vat_validated_at', null)
45
            ->setAllowedTypes('vat_validated_at', ['null', 'string'])
46
        ;
47
    }
48
}
49