Passed
Push — master ( 54a2b1...4e6567 )
by Luiz Kim
17:49 queued 15:14
created

Theme::getColors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace ControleOnline\Entity;
4
5
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Doctrine\Orm\Filter\OrderFilter 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...
6
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Doctrine\Orm\Filter\SearchFilter 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...
7
use ApiPlatform\Metadata\ApiFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\ApiFilter 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...
8
use ApiPlatform\Metadata\ApiResource;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\ApiResource 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...
9
use ApiPlatform\Metadata\Get;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Get 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...
10
use ApiPlatform\Metadata\GetCollection;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\GetCollection 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...
11
use ControleOnline\Controller\GetThemeColorsAction;
12
use ControleOnline\Listener\LogListener;
13
use ControleOnline\Repository\ThemeRepository;
14
use Doctrine\ORM\Mapping as ORM;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Mapping 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...
15
use Symfony\Component\Serializer\Attribute\Groups;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serializer\Attribute\Groups 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...
16
17
#[ApiResource(
18
    operations: [
19
        new Get(security: 'is_granted(\'ROLE_CLIENT\')'),
20
        new GetCollection(security: 'is_granted(\'ROLE_CLIENT\')'),
21
        new GetCollection(
22
            security: 'is_granted(\'PUBLIC_ACCESS\')',
23
            uriTemplate: '/themes-colors.css',
24
            controller: GetThemeColorsAction::class
25
        ),
26
    ],
27
    formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => ['text/csv'], 'css' => ['text/css']],
28
    normalizationContext: ['groups' => ['theme:read']],
29
    denormalizationContext: ['groups' => ['theme:write']]
30
)]
31
#[ApiFilter(filterClass: OrderFilter::class, properties: ['theme' => 'ASC'])]
32
#[ApiFilter(
33
    filterClass: SearchFilter::class,
34
    properties: [
35
        'theme' => 'partial',
36
        'state.uf' => 'exact'
37
    ]
38
)]
39
#[ORM\Table(name: 'theme')]
40
#[ORM\EntityListeners([LogListener::class])]
41
#[ORM\Entity(repositoryClass: ThemeRepository::class)]
42
class Theme
43
{
44
    #[ORM\Column(name: 'id', type: 'integer', nullable: false)]
45
    #[ORM\Id]
46
    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
47
    #[Groups(['theme:read'])]
48
    private int $id;
49
50
    #[ORM\Column(name: 'theme', type: 'string', length: 80, nullable: false)]
51
    #[Groups(['theme:read'])]
52
    private string $theme;
53
54
    #[ORM\Column(name: 'background', type: 'integer', nullable: true)]
55
    #[Groups(['theme:read'])]
56
    private ?int $background = null;
57
58
    #[ORM\Column(name: 'colors', type: 'json', nullable: false)]
59
    #[Groups(['theme:read'])]
60
    private array $colors;
61
62
    public function getId(): int
63
    {
64
        return $this->id;
65
    }
66
67
    public function setTheme(string $theme): self
68
    {
69
        $this->theme = $theme;
70
        return $this;
71
    }
72
73
    public function getTheme(): string
74
    {
75
        return strtoupper($this->theme);
76
    }
77
78
    public function getBackground(): ?int
79
    {
80
        return $this->background;
81
    }
82
83
    public function setBackground(?int $background): self
84
    {
85
        $this->background = $background;
86
        return $this;
87
    }
88
89
    public function getColors(bool $decode = false): mixed
90
    {
91
        return $decode ? (object) json_decode(json_encode($this->colors)) : $this->colors;
92
    }
93
94
    public function setColors(array $colors): self
95
    {
96
        $this->colors = $colors;
97
        return $this;
98
    }
99
100
    public function addColors(string $key, mixed $value): self
101
    {
102
        $colors = $this->getColors(true);
103
        $colors->$key = $value;
104
        $this->colors = (array) $colors;
105
        return $this;
106
    }
107
}