PropertyCodeStrictTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 35
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCode() 0 4 1
A setCode() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the zibios/sharep.
7
 *
8
 * (c) Zbigniew Ślązak
9
 */
10
11
namespace App\Entity\Traits;
12
13
use ApiPlatform\Core\Annotation as OA;
14
use Doctrine\ORM\Mapping as ORM;
15
use Gedmo\Mapping\Annotation as Gedmo;
16
use Symfony\Component\Serializer\Annotation as SA;
17
use Symfony\Component\Validator\Constraints as Assert;
18
19
trait PropertyCodeStrictTrait
20
{
21
    /**
22
     * @var string Code, lowercase
23
     * @ORM\Column(name="code", type="string", length=50, nullable=false)
24
     * @Assert\NotBlank()
25
     * @OA\ApiProperty(
26
     *    attributes={
27
     *        "swagger_context"={
28
     *            "example"="CODE"
29
     *        }
30
     *     }
31
     * )
32
     * @Gedmo\Versioned
33
     * @OA\ApiFilter(ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, strategy="partial")
34
     * @SA\Groups({"read"})
35
     */
36
    private $code = '';
37
38 1
    public function getCode(): string
39
    {
40 1
        return $this->code;
41
    }
42
43 1
    public function setCode(string $code): self
44
    {
45 1
        if ('' !== $this->code) {
46 1
            throw new \OverflowException(sprintf('Code "%s" already set, can\'t be changed to "%s"!', $this->code, $code));
47
        }
48
49 1
        $this->code = strtoupper(trim($code));
50
51 1
        return $this;
52
    }
53
}
54