@@ -17,8 +17,9 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function discoveryBotUser(): void |
| 19 | 19 | { |
| 20 | - if (!self::$botUser) |
|
| 21 | - $bots = ['R2D2', 'C3PO', 'T800', 'SkyNet']; |
|
| 20 | + if (!self::$botUser) { |
|
| 21 | + $bots = ['R2D2', 'C3PO', 'T800', 'SkyNet']; |
|
| 22 | + } |
|
| 22 | 23 | |
| 23 | 24 | $online = array_rand($bots); |
| 24 | 25 | $bot = $bots[$online]; |
@@ -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); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public function addLine($prefix = '', $suffix = '', $delimiter = ' ') |
| 33 | 33 | { |
| 34 | 34 | $initialSpace = str_repeat(" ", $this->initialSpace); |
| 35 | - $count = $this->totalChars - $this->initialSpace - strlen($prefix) - strlen($suffix); |
|
| 35 | + $count = $this->totalChars - $this->initialSpace - strlen($prefix) - strlen($suffix); |
|
| 36 | 36 | if ($count > 0) |
| 37 | 37 | $delimiter = str_repeat($delimiter, $count); |
| 38 | 38 | $this->text .= $initialSpace . $prefix . $delimiter . $suffix . "\n"; |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | public function generatePrintData(Device $device, People $provider, ?array $aditionalData = []): Spool |
| 51 | 51 | { |
| 52 | 52 | $printer = null; |
| 53 | - $device_config = $this->deviceService->discoveryDeviceConfig($device, $provider)->getConfigs(true); |
|
| 53 | + $device_config = $this->deviceService->discoveryDeviceConfig($device, $provider)->getConfigs(true); |
|
| 54 | 54 | if (isset($device_config['printer'])) |
| 55 | 55 | $printer = $this->deviceService->discoveryDevice($device_config['printer']); |
| 56 | 56 | |
| 57 | - $content = [ |
|
| 57 | + $content = [ |
|
| 58 | 58 | "operation" => "PRINT_TEXT", |
| 59 | 59 | "styles" => [[]], |
| 60 | 60 | "value" => [$this->text] |
@@ -33,8 +33,9 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | $initialSpace = str_repeat(" ", $this->initialSpace); |
| 35 | 35 | $count = $this->totalChars - $this->initialSpace - strlen($prefix) - strlen($suffix); |
| 36 | - if ($count > 0) |
|
| 37 | - $delimiter = str_repeat($delimiter, $count); |
|
| 36 | + if ($count > 0) { |
|
| 37 | + $delimiter = str_repeat($delimiter, $count); |
|
| 38 | + } |
|
| 38 | 39 | $this->text .= $initialSpace . $prefix . $delimiter . $suffix . "\n"; |
| 39 | 40 | } |
| 40 | 41 | |
@@ -51,8 +52,9 @@ discard block |
||
| 51 | 52 | { |
| 52 | 53 | $printer = null; |
| 53 | 54 | $device_config = $this->deviceService->discoveryDeviceConfig($device, $provider)->getConfigs(true); |
| 54 | - if (isset($device_config['printer'])) |
|
| 55 | - $printer = $this->deviceService->discoveryDevice($device_config['printer']); |
|
| 55 | + if (isset($device_config['printer'])) { |
|
| 56 | + $printer = $this->deviceService->discoveryDevice($device_config['printer']); |
|
| 57 | + } |
|
| 56 | 58 | |
| 57 | 59 | $content = [ |
| 58 | 60 | "operation" => "PRINT_TEXT", |
@@ -62,8 +64,9 @@ discard block |
||
| 62 | 64 | |
| 63 | 65 | $printData = $this->addToSpool($printer ?: $device, json_encode($content), $aditionalData); |
| 64 | 66 | |
| 65 | - if ($printer != $device) |
|
| 66 | - $x = ''; |
|
| 67 | + if ($printer != $device) { |
|
| 68 | + $x = ''; |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | return $printData; |
| 69 | 72 | } |