Passed
Push — master ( bf46cc...bf9f11 )
by Luiz Kim
02:42
created

DeviceConfig::getDevice()   A

Complexity

Conditions 1
Paths 1

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