@@ -15,12 +15,12 @@ discard block  | 
                                                    ||
| 15 | 15 | /**  | 
                                                        
| 16 | 16 | * @var array<string>  | 
                                                        
| 17 | 17 | */  | 
                                                        
| 18 | - private array $relations= [];  | 
                                                        |
| 18 | + private array $relations = [];  | 
                                                        |
| 19 | 19 | |
| 20 | 20 | private AbstractSchemaManager $SchemaManager;  | 
                                                        
| 21 | 21 | private ModelManager $modelManager;  | 
                                                        
| 22 | 22 | |
| 23 | - public function __construct(\Doctrine\DBAL\Connection $connection,ModelManager $modelManager)  | 
                                                        |
| 23 | + public function __construct(\Doctrine\DBAL\Connection $connection, ModelManager $modelManager)  | 
                                                        |
| 24 | 24 |      { | 
                                                        
| 25 | 25 | $this->modelManager = $modelManager;  | 
                                                        
| 26 | 26 | $this->SchemaManager = $connection->createSchemaManager();  | 
                                                        
@@ -36,12 +36,12 @@ discard block  | 
                                                    ||
| 36 | 36 | public function from($table, $alias = null): QueryBuilder  | 
                                                        
| 37 | 37 |      { | 
                                                        
| 38 | 38 | $this->table = $table;  | 
                                                        
| 39 | - return parent::from($table,$alias);  | 
                                                        |
| 39 | + return parent::from($table, $alias);  | 
                                                        |
| 40 | 40 | }  | 
                                                        
| 41 | 41 | |
| 42 | 42 | public function get(): Collection  | 
                                                        
| 43 | 43 |      { | 
                                                        
| 44 | -        if(!$this->SchemaManager->tableExists($this->table)){ | 
                                                        |
| 44 | +        if (!$this->SchemaManager->tableExists($this->table)) { | 
                                                        |
| 45 | 45 | return Collection::fromIterable([]);  | 
                                                        
| 46 | 46 | }  | 
                                                        
| 47 | 47 | $model = $this->modelManager->create($this->table);  | 
                                                        
@@ -55,9 +55,9 @@ discard block  | 
                                                    ||
| 55 | 55 | ->map(static fn($value): Model => ($model)->setLoadedProperties($value)->with($relations)->setLoaded());  | 
                                                        
| 56 | 56 | }  | 
                                                        
| 57 | 57 | |
| 58 | - public function first(): Model|null  | 
                                                        |
| 58 | + public function first(): Model | null  | 
                                                        |
| 59 | 59 |      { | 
                                                        
| 60 | -        if(!$this->SchemaManager->tableExists($this->table)){ | 
                                                        |
| 60 | +        if (!$this->SchemaManager->tableExists($this->table)) { | 
                                                        |
| 61 | 61 | return null;  | 
                                                        
| 62 | 62 | }  | 
                                                        
| 63 | 63 | $relations = $this->relations;  | 
                                                        
@@ -69,16 +69,16 @@ discard block  | 
                                                    ||
| 69 | 69 |      { | 
                                                        
| 70 | 70 | $table = new Table($model->getName());  | 
                                                        
| 71 | 71 |          if ($this->isUsingUUID) { | 
                                                        
| 72 | -            $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true,'comment' => 'string']); | 
                                                        |
| 72 | +            $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true, 'comment' => 'string']); | 
                                                        |
| 73 | 73 |          } else { | 
                                                        
| 74 | -            $table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true,'comment' => 'integer']); | 
                                                        |
| 74 | +            $table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true, 'comment' => 'integer']); | 
                                                        |
| 75 | 75 | }  | 
                                                        
| 76 | 76 |          $table->setPrimaryKey(array("id")); | 
                                                        
| 77 | 77 | $types = $model->getTypes();  | 
                                                        
| 78 | 78 |          foreach ($model->getProperties() as $key => $value) { | 
                                                        
| 79 | 79 |              if ($key != 'id') { | 
                                                        
| 80 | 80 | |
| 81 | - $table->addColumn($key,$types[$key] , ['notnull' => false, 'comment' => $types[$key]]);  | 
                                                        |
| 81 | + $table->addColumn($key, $types[$key], ['notnull' => false, 'comment' => $types[$key]]);  | 
                                                        |
| 82 | 82 | }  | 
                                                        
| 83 | 83 | }  | 
                                                        
| 84 | 84 | return $table;  | 
                                                        
@@ -129,7 +129,7 @@ discard block  | 
                                                    ||
| 129 | 129 |          try { | 
                                                        
| 130 | 130 | $this->getTable($table_name);  | 
                                                        
| 131 | 131 | return true;  | 
                                                        
| 132 | -        }catch(TableDoesNotExist $e){ | 
                                                        |
| 132 | +        } catch (TableDoesNotExist $e) { | 
                                                        |
| 133 | 133 | return false;  | 
                                                        
| 134 | 134 | }  | 
                                                        
| 135 | 135 | }  | 
                                                        
@@ -59,10 +59,10 @@ discard block  | 
                                                    ||
| 59 | 59 | */  | 
                                                        
| 60 | 60 | public function registerEvents(): void  | 
                                                        
| 61 | 61 |      { | 
                                                        
| 62 | -        Event::subscribeTo('__arca.model.save.'.$this->connection->getConnectionId(), function ($model) { | 
                                                        |
| 62 | +        Event::subscribeTo('__arca.model.save.'.$this->connection->getConnectionId(), function($model) { | 
                                                        |
| 63 | 63 | return $this->save($model);  | 
                                                        
| 64 | 64 | });  | 
                                                        
| 65 | -        Event::subscribeTo('__arca.model.delete.'.$this->connection->getConnectionId(), function ($model) { | 
                                                        |
| 65 | +        Event::subscribeTo('__arca.model.delete.'.$this->connection->getConnectionId(), function($model) { | 
                                                        |
| 66 | 66 | return $this->delete($model);  | 
                                                        
| 67 | 67 | });  | 
                                                        
| 68 | 68 | }  | 
                                                        
@@ -74,7 +74,7 @@ discard block  | 
                                                    ||
| 74 | 74 | * @param array<mixed> $params  | 
                                                        
| 75 | 75 | * @return int|numeric-string  | 
                                                        
| 76 | 76 | */  | 
                                                        
| 77 | - public function exec(string $sql, array $params=array()): int|string  | 
                                                        |
| 77 | + public function exec(string $sql, array $params = array()): int | string  | 
                                                        |
| 78 | 78 |      { | 
                                                        
| 79 | 79 | return $this->connection->executeStatement($sql, $params);  | 
                                                        
| 80 | 80 | }  | 
                                                        
@@ -86,7 +86,7 @@ discard block  | 
                                                    ||
| 86 | 86 | * @param array<mixed> $params  | 
                                                        
| 87 | 87 | * @return array<int,array<string,mixed>>  | 
                                                        
| 88 | 88 | */  | 
                                                        
| 89 | - public function getAll(string $sql, array $params=[]): array  | 
                                                        |
| 89 | + public function getAll(string $sql, array $params = []): array  | 
                                                        |
| 90 | 90 |      { | 
                                                        
| 91 | 91 | return $this->connection->executeQuery($sql, $params)->fetchAllAssociative();  | 
                                                        
| 92 | 92 | }  | 
                                                        
@@ -119,7 +119,7 @@ discard block  | 
                                                    ||
| 119 | 119 | |
| 120 | 120 |          try { | 
                                                        
| 121 | 121 | $id = $this->createRecords($model);  | 
                                                        
| 122 | -            $model->set('id',$id); | 
                                                        |
| 122 | +            $model->set('id', $id); | 
                                                        |
| 123 | 123 | $model->setLoaded();  | 
                                                        
| 124 | 124 | $this->connection->commit();  | 
                                                        
| 125 | 125 |          } catch (\Exception $e) { | 
                                                        
@@ -293,7 +293,7 @@ discard block  | 
                                                    ||
| 293 | 293 | * @param mixed $id  | 
                                                        
| 294 | 294 | * @return Model  | 
                                                        
| 295 | 295 | */  | 
                                                        
| 296 | - public function getOne(string $table, mixed $id) : Model|null  | 
                                                        |
| 296 | + public function getOne(string $table, mixed $id) : Model | null  | 
                                                        |
| 297 | 297 |      { | 
                                                        
| 298 | 298 | return $this->connection->getRecordManager()->getById($table, $id);  | 
                                                        
| 299 | 299 | }  | 
                                                        
@@ -45,7 +45,7 @@ discard block  | 
                                                    ||
| 45 | 45 | * @param string $name  | 
                                                        
| 46 | 46 | * @param Connection $connection  | 
                                                        
| 47 | 47 | */  | 
                                                        
| 48 | - public function __construct(string $name,Connection $connection)  | 
                                                        |
| 48 | + public function __construct(string $name, Connection $connection)  | 
                                                        |
| 49 | 49 |      { | 
                                                        
| 50 | 50 | |
| 51 | 51 | $this->table = $name;  | 
                                                        
@@ -115,12 +115,12 @@ discard block  | 
                                                    ||
| 115 | 115 | }  | 
                                                        
| 116 | 116 | |
| 117 | 117 | $type = gettype($val);  | 
                                                        
| 118 | -        if($type == 'array' || $type == 'object'){ | 
                                                        |
| 118 | +        if ($type == 'array' || $type == 'object') { | 
                                                        |
| 119 | 119 |              $val = Type::getType('json_document')->convertToDatabaseValue($val, $this->connection->getDatabasePlatform()); | 
                                                        
| 120 | 120 | $type = 'json_document';  | 
                                                        
| 121 | 121 | }  | 
                                                        
| 122 | 122 | |
| 123 | -        if($type == 'string'){ | 
                                                        |
| 123 | +        if ($type == 'string') { | 
                                                        |
| 124 | 124 | $type = 'text';  | 
                                                        
| 125 | 125 | }  | 
                                                        
| 126 | 126 | |
@@ -165,20 +165,20 @@ discard block  | 
                                                    ||
| 165 | 165 |              $parts = \Safe\preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); | 
                                                        
| 166 | 166 |              if (strtolower($parts[0]) == 'own') { | 
                                                        
| 167 | 167 |                  if (strtolower($parts[2]) == 'list') { | 
                                                        
| 168 | - return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get();  | 
                                                        |
| 168 | + return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get();  | 
                                                        |
| 169 | 169 | }  | 
                                                        
| 170 | 170 | }  | 
                                                        
| 171 | 171 |              if (strtolower($parts[0]) == 'shared') { | 
                                                        
| 172 | 172 |                  if (strtolower($parts[2]) == 'list') { | 
                                                        
| 173 | - $rel_table = $this->connection->getTableManager()->tableExists($this->table . '_' . strtolower($parts[1])) ? $this->table . '_' . strtolower($parts[1]) : strtolower($parts[1]) . '_' . $this->table;  | 
                                                        |
| 174 | - $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get();  | 
                                                        |
| 173 | + $rel_table = $this->connection->getTableManager()->tableExists($this->table.'_'.strtolower($parts[1])) ? $this->table.'_'.strtolower($parts[1]) : strtolower($parts[1]).'_'.$this->table;  | 
                                                        |
| 174 | + $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get();  | 
                                                        |
| 175 | 175 | $rel_ids = '';  | 
                                                        
| 176 | 176 |                      foreach ($relations as $relation) { | 
                                                        
| 177 | - $key = strtolower($parts[1]) . '_id';  | 
                                                        |
| 178 | - $rel_ids .= "'" . $relation->$key . "',";  | 
                                                        |
| 177 | + $key = strtolower($parts[1]).'_id';  | 
                                                        |
| 178 | + $rel_ids .= "'".$relation->$key."',";  | 
                                                        |
| 179 | 179 | }  | 
                                                        
| 180 | 180 | $rel_ids = substr($rel_ids, 0, -1);  | 
                                                        
| 181 | -                    return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN (' . $rel_ids . ')')->get(); | 
                                                        |
| 181 | +                    return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN ('.$rel_ids.')')->get(); | 
                                                        |
| 182 | 182 | }  | 
                                                        
| 183 | 183 | }  | 
                                                        
| 184 | 184 | }  | 
                                                        
@@ -188,8 +188,8 @@ discard block  | 
                                                    ||
| 188 | 188 | return $type->convertToPHPValue($this->__properties[$key], $this->connection->getDatabasePlatform());  | 
                                                        
| 189 | 189 | }  | 
                                                        
| 190 | 190 | |
| 191 | -        if (array_key_exists($key . '_id', $this->__properties)) { | 
                                                        |
| 192 | - return $this->connection->getRecordManager()->getById($key, $this->__properties[$key . '_id']);  | 
                                                        |
| 191 | +        if (array_key_exists($key.'_id', $this->__properties)) { | 
                                                        |
| 192 | + return $this->connection->getRecordManager()->getById($key, $this->__properties[$key.'_id']);  | 
                                                        |
| 193 | 193 | }  | 
                                                        
| 194 | 194 | |
| 195 | 195 | throw new Exception\KeyNotFoundException();  | 
                                                        
@@ -352,7 +352,7 @@ discard block  | 
                                                    ||
| 352 | 352 | */  | 
                                                        
| 353 | 353 | public function save(): mixed  | 
                                                        
| 354 | 354 |      { | 
                                                        
| 355 | -        if($this->__meta['id_error']){ | 
                                                        |
| 355 | +        if ($this->__meta['id_error']) { | 
                                                        |
| 356 | 356 | throw new Exception\InvalidIdException();  | 
                                                        
| 357 | 357 | }  | 
                                                        
| 358 | 358 |          Event::dispatch('__arca.model.save.'.$this->connection->getConnectionId(), [$this]); |