@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | } |
28 | 28 | |
29 | 29 | |
30 | - public function getEntityByExtraData(ExtraFields $extraFields, string $code, object | string $entity) |
|
30 | + public function getEntityByExtraData(ExtraFields $extraFields, string $code, object | string $entity) |
|
31 | 31 | { |
32 | 32 | $class = $this->getEntityName($entity); |
33 | 33 | $extraData = $this->manager->getRepository(ExtraData::class)->findOneBy([ |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | - public function discoveryExtraData(int|string $entityId, ExtraFields $extraFields, string $code, object | string $entity) |
|
45 | + public function discoveryExtraData(int | string $entityId, ExtraFields $extraFields, string $code, object | string $entity) |
|
46 | 46 | { |
47 | 47 | $class = $this->getEntityName($entity); |
48 | 48 | |
49 | - $extraData = $this->getEntityByExtraData($extraFields, $code, $entity); |
|
49 | + $extraData = $this->getEntityByExtraData($extraFields, $code, $entity); |
|
50 | 50 | if ($extraData) return $extraData; |
51 | 51 | |
52 | 52 | $extraData = new ExtraData(); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | return $this->manager->getRepository($class->getName())->find($extraData->getEntityId()); |
61 | 61 | } |
62 | 62 | |
63 | - public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
63 | + public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
64 | 64 | { |
65 | 65 | |
66 | 66 | $extraFields = $this->manager->getRepository(ExtraFields::class)->findOneBy([ |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | //$this->manager->persist($entity); |
138 | 138 | } else { |
139 | - $json = json_decode($this->request->getContent(), true); |
|
139 | + $json = json_decode($this->request->getContent(), true); |
|
140 | 140 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
141 | 141 | if (!$extra_data) |
142 | 142 | return; |
@@ -35,8 +35,9 @@ discard block |
||
35 | 35 | 'entity_name' => $class->getShortName(), |
36 | 36 | 'value' => $code |
37 | 37 | ]); |
38 | - if ($extraData) |
|
39 | - return $this->manager->getRepository($class->getName())->find($extraData->getEntityId()); |
|
38 | + if ($extraData) { |
|
39 | + return $this->manager->getRepository($class->getName())->find($extraData->getEntityId()); |
|
40 | + } |
|
40 | 41 | |
41 | 42 | return null; |
42 | 43 | } |
@@ -47,7 +48,9 @@ discard block |
||
47 | 48 | $class = $this->getEntityName($entity); |
48 | 49 | |
49 | 50 | $extraData = $this->getEntityByExtraData($extraFields, $code, $entity); |
50 | - if ($extraData) return $extraData; |
|
51 | + if ($extraData) { |
|
52 | + return $extraData; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | $extraData = new ExtraData(); |
53 | 56 | $extraData->setEntityId($entityId); |
@@ -91,12 +94,15 @@ discard block |
||
91 | 94 | |
92 | 95 | public function discoveryDevice(&$entity) |
93 | 96 | { |
94 | - if ($entity instanceof Device || $entity instanceof DeviceConfig || !$this->request->headers) |
|
95 | - return; |
|
97 | + if ($entity instanceof Device || $entity instanceof DeviceConfig || !$this->request->headers) { |
|
98 | + return; |
|
99 | + } |
|
96 | 100 | |
97 | 101 | $deviceId = $this->request->headers->get('DEVICE') ?: $this->getUserIp(); |
98 | 102 | if (method_exists($entity, 'setDevice')) { |
99 | - if ($entity->getDevice()) return; |
|
103 | + if ($entity->getDevice()) { |
|
104 | + return; |
|
105 | + } |
|
100 | 106 | $device = $this->deviceService->discoveryDevice($deviceId); |
101 | 107 | $entity->setDevice($device); |
102 | 108 | } |
@@ -107,14 +113,16 @@ discard block |
||
107 | 113 | $token = $this->security->getToken(); |
108 | 114 | $user = $token ? $token->getUser() : $this->skyNetService->getBotUser(); |
109 | 115 | |
110 | - if (method_exists($entity, 'setUser') && !$entity->getUser()) |
|
111 | - $entity->setUser($user); |
|
116 | + if (method_exists($entity, 'setUser') && !$entity->getUser()) { |
|
117 | + $entity->setUser($user); |
|
118 | + } |
|
112 | 119 | } |
113 | 120 | |
114 | 121 | public function persist(&$entity) |
115 | 122 | { |
116 | - if (self::$persisted == true) |
|
117 | - return; |
|
123 | + if (self::$persisted == true) { |
|
124 | + return; |
|
125 | + } |
|
118 | 126 | self::$persisted = true; |
119 | 127 | |
120 | 128 | //$this->manager->persist($entity); |
@@ -138,15 +146,17 @@ discard block |
||
138 | 146 | } else { |
139 | 147 | $json = json_decode($this->request->getContent(), true); |
140 | 148 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
141 | - if (!$extra_data) |
|
142 | - return; |
|
149 | + if (!$extra_data) { |
|
150 | + return; |
|
151 | + } |
|
143 | 152 | $entity_id = $extra_data['entity_id']; |
144 | 153 | $entity_name = $extra_data['entity_name']; |
145 | 154 | } |
146 | 155 | |
147 | 156 | |
148 | - if (!$entity_id || !$entity_name) |
|
149 | - return; |
|
157 | + if (!$entity_id || !$entity_name) { |
|
158 | + return; |
|
159 | + } |
|
150 | 160 | |
151 | 161 | foreach ($extra_data['data'] as $key => $data) { |
152 | 162 | $extra_fields = $this->manager->getRepository(ExtraFields::class)->find($key); |
@@ -157,8 +167,9 @@ discard block |
||
157 | 167 | 'extra_fields' => $extra_fields |
158 | 168 | ]); |
159 | 169 | |
160 | - if (!$extraData) |
|
161 | - $extraData = new ExtraData(); |
|
170 | + if (!$extraData) { |
|
171 | + $extraData = new ExtraData(); |
|
172 | + } |
|
162 | 173 | |
163 | 174 | $extraData->setExtraFields($extra_fields); |
164 | 175 | $extraData->setEntityName($entity_name); |