VatNumberAwareTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 61
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getVatNumber() 0 3 1
A getVatValidatedAt() 0 3 1
A setVatNumber() 0 3 1
A hasValidVatNumber() 0 3 2
A hasVatNumber() 0 3 2
A setVatValid() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewebe\SyliusVATPlugin\Entity;
6
7
use DateTime;
8
use Doctrine\DBAL\Types\Types;
9
use Doctrine\ORM\Mapping as ORM;
10
use Gedmo\Mapping\Annotation as Gedmo;
11
use Symfony\Component\Serializer\Annotation\Groups;
12
use TestApplication\src\Entity\Addressing\Address;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Gewebe\SyliusVATPlugin\Entity\Address. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
Bug introduced by
The type TestApplication\src\Entity\Addressing\Address was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
/**
15
 * Trait that implements the vat number functionality
16
 * Used in:
17
 * <li>@see Address</li>
18
 */
19
trait VatNumberAwareTrait
20
{
21
    /**
22
     * @ORM\Column(name="vat_number", type="string", nullable=true)
23
     *
24
     * @Gedmo\Versioned()
25
     *
26
     * @Groups({"shop:address:read", "shop:address:create", "shop:address:update"})
27
     */
28
    #[ORM\Column(name: 'vat_number', type: Types::STRING, nullable: true)]
29
    #[Gedmo\Versioned()]
30
    #[Groups(['shop:address:read', 'shop:address:create', 'shop:address:update'])]
31
    protected ?string $vatNumber = null;
32
33
    /**
34
     * @ORM\Column(name="vat_valid", type="boolean")
35
     *
36
     * @Groups({"shop:address:read"})
37
     */
38
    #[ORM\Column(name: 'vat_valid', type: Types::BOOLEAN)]
39
    #[Groups(['shop:address:read'])]
40
    protected bool $vatValid = false;
41
42
    /**
43
     * @ORM\Column(name="vat_validated_at", type="datetime", nullable=true)
44
     *
45
     * @Groups({"shop:address:read"})
46
     */
47
    #[ORM\Column(name: 'vat_validated_at', type: Types::DATETIME_MUTABLE, nullable: true)]
48
    #[Groups(['shop:address:read'])]
49
    protected ?DateTime $vatValidatedAt = null;
50
51
    public function getVatNumber(): ?string
52
    {
53
        return $this->vatNumber;
54
    }
55
56
    public function setVatNumber(?string $vatNumber): void
57
    {
58
        $this->vatNumber = $vatNumber;
59
    }
60
61
    public function hasVatNumber(): bool
62
    {
63
        return is_string($this->vatNumber) && strlen($this->vatNumber) > 0;
64
    }
65
66
    public function hasValidVatNumber(): bool
67
    {
68
        return $this->hasVatNumber() && $this->vatValid === true;
69
    }
70
71
    public function setVatValid(bool $valid, ?DateTime $validatedAt = null): void
72
    {
73
        $this->vatValid = $valid;
74
        $this->vatValidatedAt = $validatedAt ?? new DateTime();
75
    }
76
77
    public function getVatValidatedAt(): ?DateTime
78
    {
79
        return $this->vatValidatedAt;
80
    }
81
}
82