Passed
Push — master ( 9f430e...5248ed )
by Luiz Kim
02:41 queued 15s
created

DeviceConfig::addConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace ControleOnline\Entity;
4
5
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...
6
use ApiPlatform\Metadata\Post;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Post 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\Delete;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Delete 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\Put;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Put 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\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...
11
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...
12
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...
13
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...
14
use ControleOnline\Controller\AddDeviceConfigAction;
15
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...
16
use stdClass;
17
use Symfony\Component\Serializer\Annotation\Groups;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serializer\Annotation\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...
18
use Symfony\Component\Validator\Constraints as Assert;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraints 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...
19
20
/**
21
 * @ORM\EntityListeners ({ControleOnline\Listener\LogListener::class})
22
 * @ORM\Table (name="device_configs")
23
 * @ORM\Entity (repositoryClass="ControleOnline\Repository\DeviceConfigRepository")
24
 */
25
#[ApiResource(
26
    operations: [
27
        new Get(security: 'is_granted(\'ROLE_ADMIN\') or is_granted(\'ROLE_CLIENT\')'),
28
        new Put(
29
            security: 'is_granted(\'ROLE_CLIENT\')',
30
            denormalizationContext: ['groups' => ['device_config:write']]
31
        ),
32
        new Post(
33
            security: 'is_granted(\'ROLE_CLIENT\')',
34
            uriTemplate: '/device_configs/add-configs',
35
            controller: AddDeviceConfigAction::class
36
        ),        
37
        new Delete(security: 'is_granted(\'ROLE_CLIENT\')'),
38
        new Post(securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')'),
39
        new GetCollection(
40
            security: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')',
41
        )
42
    ],
43
    formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => ['text/csv']],
44
    normalizationContext: ['groups' => ['device_config:read']],
45
    denormalizationContext: ['groups' => ['device_config:write']]
46
)]
47
#[ApiFilter(filterClass: OrderFilter::class, properties: ['id' => 'ASC'])]
48
49
class DeviceConfig
50
{
51
    /**
52
     * @var integer
53
     *
54
     * @ORM\Column(name="id", type="integer", nullable=false)
55
     * @ORM\Id
56
     * @ORM\GeneratedValue(strategy="IDENTITY")
57
     * @Groups({"device_config:read","device:read","device_config:write"})
58
     */
59
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['id' => 'exact'])]
60
61
    private $id;
62
63
64
    /**
65
     * @var \ControleOnline\Entity\People
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\People 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...
66
     *
67
     * @ORM\ManyToOne(targetEntity="ControleOnline\Entity\People")
68
     * @ORM\JoinColumns({
69
     *   @ORM\JoinColumn(name="people_id", referencedColumnName="id", nullable=false)
70
     * })
71
     * @Groups({"device_config:read","device:read","device_config:write"})
72
     */
73
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['people' => 'exact'])]
74
75
    private $people;
76
    /**
77
     * @var \ControleOnline\Entity\Device
78
     *
79
     * @ORM\ManyToOne(targetEntity="ControleOnline\Entity\Device")
80
     * @ORM\JoinColumns({
81
     *   @ORM\JoinColumn(name="device_id", referencedColumnName="id", nullable=false)
82
     * })
83
     * @Groups({"device_config:read","device:read","device_config:write"})
84
     */
85
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['device' => 'exact'])]
86
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['device.device' => 'exact'])]
87
    private $device;
88
89
90
    /**
91
     * @var string
92
     *
93
     * @ORM\Column(name="configs", type="string", length=100, nullable=false)
94
     * @Groups({"device_config:read","device:read","device_config:write"})
95
     * @Assert\NotBlank
96
     */
97
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['configs' => 'exact'])]
98
99
    private $configs;
100
    public function __construct()
101
    {
102
        $this->configs = json_encode(new stdClass());
103
    }
104
105
    /**
106
     * Get the value of id
107
     */
108
    public function getId()
109
    {
110
        return $this->id;
111
    }
112
113
    /**
114
     * Get the value of people
115
     */
116
    public function getPeople()
117
    {
118
        return $this->people;
119
    }
120
121
    /**
122
     * Set the value of people
123
     */
124
    public function setPeople($people): self
125
    {
126
        $this->people = $people;
127
128
        return $this;
129
    }
130
131
132
133
134
135
    public function getConfigs($decode = false)
136
    {
137
        return $decode ? json_decode((is_array($this->configs) ? json_encode($this->configs) : $this->configs), true) : $this->configs;
0 ignored issues
show
introduced by
The condition is_array($this->configs) is always false.
Loading history...
138
    }
139
140
141
    public function addConfig($key, $value)
142
    {
143
        $configs = $this->getConfigs(true);
144
        $configs[$key] = $value;
145
        return $this->setConfigs($configs);
146
    }
147
148
149
    public function setConfigs($configs)
150
    {
151
        $this->configs = json_encode($configs);
152
        return $this;
153
    }
154
155
    /**
156
     * Get the value of device
157
     */
158
    public function getDevice()
159
    {
160
        return $this->device;
161
    }
162
163
    /**
164
     * Set the value of device
165
     */
166
    public function setDevice($device): self
167
    {
168
        $this->device = $device;
169
170
        return $this;
171
    }
172
}
173