@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | return null; |
44 | 44 | } |
45 | 45 | |
46 | - public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
46 | + public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
47 | 47 | { |
48 | 48 | |
49 | 49 | $extraFields = $this->manager->getRepository(ExtraFields::class)->findOneBy([ |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | //$this->manager->persist($entity); |
118 | 118 | } else { |
119 | - $json = json_decode($this->request->getContent(), true); |
|
119 | + $json = json_decode($this->request->getContent(), true); |
|
120 | 120 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
121 | 121 | if (!$extra_data) |
122 | 122 | return; |
@@ -37,8 +37,9 @@ discard block |
||
37 | 37 | 'entity_name' => $class->getShortName(), |
38 | 38 | 'value' => $code |
39 | 39 | ]); |
40 | - if ($extraData) |
|
41 | - return $this->manager->getRepository($class::class)->find($extraData->getEntityId()); |
|
40 | + if ($extraData) { |
|
41 | + return $this->manager->getRepository($class::class)->find($extraData->getEntityId()); |
|
42 | + } |
|
42 | 43 | |
43 | 44 | return null; |
44 | 45 | } |
@@ -52,8 +53,9 @@ discard block |
||
52 | 53 | 'context' => $context |
53 | 54 | ]); |
54 | 55 | |
55 | - if (!$extraFields) |
|
56 | - $extraFields = new ExtraFields(); |
|
56 | + if (!$extraFields) { |
|
57 | + $extraFields = new ExtraFields(); |
|
58 | + } |
|
57 | 59 | |
58 | 60 | $extraFields->setName($fieldName); |
59 | 61 | $extraFields->setContext($context); |
@@ -74,12 +76,15 @@ discard block |
||
74 | 76 | |
75 | 77 | public function discoveryDevice(&$entity) |
76 | 78 | { |
77 | - if ($entity instanceof Device || $entity instanceof DeviceConfig || !$this->request->headers) |
|
78 | - return; |
|
79 | + if ($entity instanceof Device || $entity instanceof DeviceConfig || !$this->request->headers) { |
|
80 | + return; |
|
81 | + } |
|
79 | 82 | |
80 | 83 | $deviceId = $this->request->headers->get('DEVICE') ?: $this->getUserIp(); |
81 | 84 | if (method_exists($entity, 'setDevice')) { |
82 | - if ($entity->getDevice()) return; |
|
85 | + if ($entity->getDevice()) { |
|
86 | + return; |
|
87 | + } |
|
83 | 88 | $device = $this->deviceService->discoveryDevice($deviceId); |
84 | 89 | $entity->setDevice($device); |
85 | 90 | } |
@@ -87,14 +92,16 @@ discard block |
||
87 | 92 | |
88 | 93 | public function discoveryUser(&$entity) |
89 | 94 | { |
90 | - if (method_exists($entity, 'setUser') && !$entity->getUser() && $this->security->getToken()) |
|
91 | - $entity->setUser($this->security->getToken()->getUser()); |
|
95 | + if (method_exists($entity, 'setUser') && !$entity->getUser() && $this->security->getToken()) { |
|
96 | + $entity->setUser($this->security->getToken()->getUser()); |
|
97 | + } |
|
92 | 98 | } |
93 | 99 | |
94 | 100 | public function persist(&$entity) |
95 | 101 | { |
96 | - if (self::$persisted == true) |
|
97 | - return; |
|
102 | + if (self::$persisted == true) { |
|
103 | + return; |
|
104 | + } |
|
98 | 105 | self::$persisted = true; |
99 | 106 | |
100 | 107 | //$this->manager->persist($entity); |
@@ -118,15 +125,17 @@ discard block |
||
118 | 125 | } else { |
119 | 126 | $json = json_decode($this->request->getContent(), true); |
120 | 127 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
121 | - if (!$extra_data) |
|
122 | - return; |
|
128 | + if (!$extra_data) { |
|
129 | + return; |
|
130 | + } |
|
123 | 131 | $entity_id = $extra_data['entity_id']; |
124 | 132 | $entity_name = $extra_data['entity_name']; |
125 | 133 | } |
126 | 134 | |
127 | 135 | |
128 | - if (!$entity_id || !$entity_name) |
|
129 | - return; |
|
136 | + if (!$entity_id || !$entity_name) { |
|
137 | + return; |
|
138 | + } |
|
130 | 139 | |
131 | 140 | foreach ($extra_data['data'] as $key => $data) { |
132 | 141 | $extra_fields = $this->manager->getRepository(ExtraFields::class)->find($key); |
@@ -137,8 +146,9 @@ discard block |
||
137 | 146 | 'extra_fields' => $extra_fields |
138 | 147 | ]); |
139 | 148 | |
140 | - if (!$extraData) |
|
141 | - $extraData = new ExtraData(); |
|
149 | + if (!$extraData) { |
|
150 | + $extraData = new ExtraData(); |
|
151 | + } |
|
142 | 152 | |
143 | 153 | $extraData->setExtraFields($extra_fields); |
144 | 154 | $extraData->setEntityName($entity_name); |