@@ -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); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $class = $this->getEntityName($entity); |
| 47 | 47 | |
| 48 | - $extraData = $this->getEntityByExtraData($extraFields, $code, $entity); |
|
| 48 | + $extraData = $this->getEntityByExtraData($extraFields, $code, $entity); |
|
| 49 | 49 | if (!$extraData) { |
| 50 | 50 | $extraData = new ExtraData(); |
| 51 | 51 | $extraData->setEntityId($entityId); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | return $this->manager->getRepository($class::class)->find($extraData->getEntityId()); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
| 62 | + public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
| 63 | 63 | { |
| 64 | 64 | |
| 65 | 65 | $extraFields = $this->manager->getRepository(ExtraFields::class)->findOneBy([ |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | //$this->manager->persist($entity); |
| 134 | 134 | } else { |
| 135 | - $json = json_decode($this->request->getContent(), true); |
|
| 135 | + $json = json_decode($this->request->getContent(), true); |
|
| 136 | 136 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
| 137 | 137 | if (!$extra_data) |
| 138 | 138 | return; |