Passed
Push — main ( 7af8ef...b09946 )
by Pranjal
02:54
created
src/Manager/RecordManager.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     /**
23 23
      * Create RecordManager
24 24
      */
25
-    public function __construct(Connection $connection, ModelManager $modelManager,bool $isUsingUUID = false)
25
+    public function __construct(Connection $connection, ModelManager $modelManager, bool $isUsingUUID = false)
26 26
     {
27 27
         $this->connection = $connection;
28 28
         $this->isUsingUUID = $isUsingUUID;
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     public function insert(Model $model) : mixed
38 38
     {
39 39
         if ($this->isUsingUUID) {
40
-            $model->set('id',UUID::uuid4()->toString());
40
+            $model->set('id', UUID::uuid4()->toString());
41 41
         }
42 42
         $this->connection->insert($model->getName(), $model->getSelfProperties());
43 43
         if ($this->isUsingUUID) {
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
     * @param string $table
74 74
     * @param mixed $id
75 75
     */
76
-    public function getById(string $table, mixed $id): Model|null
76
+    public function getById(string $table, mixed $id): Model | null
77 77
     {
78
-        $query =  (new QueryBuilder($this->connection,$this->modelManager))
78
+        $query = (new QueryBuilder($this->connection, $this->modelManager))
79 79
                  ->select('*')
80 80
                  ->from($table, 't')
81 81
                  ->where("t.id = '".$id."'");
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     public function getAll(string $tableName): Collection
91 91
     {
92
-        return (new QueryBuilder($this->connection,$this->modelManager))
92
+        return (new QueryBuilder($this->connection, $this->modelManager))
93 93
             ->select('*')
94 94
             ->from($tableName, 't')
95 95
             ->get();
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public function find(String $name) : QueryBuilder
103 103
     {
104
-        return (new QueryBuilder($this->connection,$this->modelManager))
104
+        return (new QueryBuilder($this->connection, $this->modelManager))
105 105
         ->select('*')
106 106
         ->from($name, 't');
107 107
     }
Please login to merge, or discard this patch.
src/Manager/TableManager.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -69,16 +69,16 @@  discard block
 block discarded – undo
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->getSelfProperties() 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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/Database.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function registerEvents(): void
62 62
     {
63
-        Event::subscribeTo('__arca.model.save.'.$this->connection->getConnectionId(), function ($model) {
63
+        Event::subscribeTo('__arca.model.save.'.$this->connection->getConnectionId(), function($model) {
64 64
             return $this->save($model);
65 65
         });
66
-        Event::subscribeTo('__arca.model.delete.'.$this->connection->getConnectionId(), function ($model) {
66
+        Event::subscribeTo('__arca.model.delete.'.$this->connection->getConnectionId(), function($model) {
67 67
             return $this->delete($model);
68 68
         });
69 69
     }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      * @param array<mixed> $params
76 76
      * @return int|numeric-string
77 77
      */
78
-    public function exec(string $sql, array $params=array()): int|string
78
+    public function exec(string $sql, array $params = array()): int | string
79 79
     {
80 80
         return  $this->connection->executeStatement($sql, $params);
81 81
     }
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      * @param array<mixed> $params
88 88
      * @return array<int,array<string,mixed>>
89 89
      */
90
-    public function getAll(string $sql, array $params=[]): array
90
+    public function getAll(string $sql, array $params = []): array
91 91
     {
92 92
         return  $this->connection->executeQuery($sql, $params)->fetchAllAssociative();
93 93
     }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
         try {
122 122
             $id = $this->createRecords($model);
123
-            $model->set('id',$id);
123
+            $model->set('id', $id);
124 124
             $this->connection->commit();
125 125
         } catch (\Exception $e) {
126 126
             $this->connection->rollBack();
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
             return $this->connection->getRecordManager()->update($model);
167 167
         }
168 168
 
169
-        if($model->hasIdError()){
169
+        if ($model->hasIdError()) {
170 170
             throw new Exception\InvalidIdException();
171 171
         }
172 172
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
      * @param mixed $id
309 309
      * @return Model
310 310
      */
311
-    public function getOne(string $table, mixed $id) : Model|null
311
+    public function getOne(string $table, mixed $id) : Model | null
312 312
     {
313 313
         return $this->connection->getRecordManager()->getById($table, $id);
314 314
     }
Please login to merge, or discard this patch.
src/Model.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      * @param string $name
53 53
      * @param Connection $connection
54 54
      */
55
-    public function __construct(string $name,Connection $connection)
55
+    public function __construct(string $name, Connection $connection)
56 56
     {
57 57
 
58 58
         $this->table = $name;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
                     $this->checkModelArray($val);
101 101
                     array_push($this->__meta['foreign_models']['otm'], $val);
102 102
                     $this->__meta['has_foreign']['otm'] = true;
103
-                    if(is_array($val) && !($val instanceof Collection)){
103
+                    if (is_array($val) && !($val instanceof Collection)) {
104 104
                         $val = Collection::fromIterable($val);
105 105
                     }
106 106
                     $this->__props[$key] = $val;
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
                 return;
109 109
             }
110 110
             if (strtolower($parts[0]) === 'shared') {
111
-                if (gettype($val) ==='array' || $val instanceof Collection) {
111
+                if (gettype($val) === 'array' || $val instanceof Collection) {
112 112
                     $this->checkModelArray($val);
113 113
                     array_push($this->__meta['foreign_models']['mtm'], $val);
114 114
                     $this->__meta['has_foreign']['mtm'] = true;
115
-                    if(is_array($val) && !($val instanceof Collection)){
115
+                    if (is_array($val) && !($val instanceof Collection)) {
116 116
                         $val = Collection::fromIterable($val);
117 117
                     }
118 118
                     $this->__props[$key] = $val;
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
             }
122 122
         }
123 123
         if ($val instanceof Model) {
124
-            if(isset($this->__props[$key.'_id'])){
124
+            if (isset($this->__props[$key.'_id'])) {
125 125
                 unset($this->__props[$key.'_id']);
126 126
             }
127 127
             $this->__meta['has_foreign']['oto'] = true;
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
             ($val) ? $val = 1 : $val = 0;
137 137
         }
138 138
 
139
-        if($type == 'array' || $type == 'object'){
139
+        if ($type == 'array' || $type == 'object') {
140 140
             $val = Type::getType('json_document')->convertToDatabaseValue($val, $this->connection->getDatabasePlatform());
141 141
             $type = 'json_document';
142 142
         }
143 143
 
144
-        if($type == 'string'){
144
+        if ($type == 'string') {
145 145
             $type = 'text';
146 146
         }
147 147
 
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
      * @throws \Scrawler\Arca\Exception\InvalidModelException
158 158
      * @return void
159 159
      */
160
-    private function checkModelArray(array|Collection $models):void{
161
-        if($models instanceof Collection){
160
+    private function checkModelArray(array | Collection $models):void{
161
+        if ($models instanceof Collection) {
162 162
             return;
163 163
         }
164 164
 
@@ -190,30 +190,30 @@  discard block
 block discarded – undo
190 190
             $parts = \Safe\preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY);
191 191
             if (strtolower($parts[0]) == 'own') {
192 192
                 if (strtolower($parts[2]) == 'list') {
193
-                    $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get();
193
+                    $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get();
194 194
                     $this->set($key, $result);
195 195
                     return $result;
196 196
                 }
197 197
             }
198 198
             if (strtolower($parts[0]) == 'shared') {
199 199
                 if (strtolower($parts[2]) == 'list') {
200
-                    $rel_table = $this->connection->getTableManager()->tableExists($this->table . '_' . strtolower($parts[1])) ? $this->table . '_' . strtolower($parts[1]) : strtolower($parts[1]) . '_' . $this->table;
201
-                    $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get();
200
+                    $rel_table = $this->connection->getTableManager()->tableExists($this->table.'_'.strtolower($parts[1])) ? $this->table.'_'.strtolower($parts[1]) : strtolower($parts[1]).'_'.$this->table;
201
+                    $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get();
202 202
                     $rel_ids = '';
203 203
                     foreach ($relations as $relation) {
204
-                        $key = strtolower($parts[1]) . '_id';
205
-                        $rel_ids .= "'" . $relation->$key . "',";
204
+                        $key = strtolower($parts[1]).'_id';
205
+                        $rel_ids .= "'".$relation->$key."',";
206 206
                     }
207 207
                     $rel_ids = substr($rel_ids, 0, -1);
208
-                    $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN (' . $rel_ids . ')')->get();
208
+                    $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN ('.$rel_ids.')')->get();
209 209
                     $this->set($key, $result);
210 210
                     return $result;
211 211
                 }
212 212
             }
213 213
         }
214 214
 
215
-        if (array_key_exists($key . '_id', $this->__properties)) {
216
-            $result = $this->connection->getRecordManager()->getById($key, $this->__properties[$key . '_id']);
215
+        if (array_key_exists($key.'_id', $this->__properties)) {
216
+            $result = $this->connection->getRecordManager()->getById($key, $this->__properties[$key.'_id']);
217 217
             $this->set($key, $result);
218 218
             return $result;
219 219
         }
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
      * Cleans up model internal state to be consistent after save
424 424
      * @return void
425 425
      */
426
-    public function cleanModel(){
426
+    public function cleanModel() {
427 427
         $this->__props = $this->__properties;
428 428
         $this->__meta['has_foreign']['oto'] = false;
429 429
         $this->__meta['has_foreign']['otm'] = false;
Please login to merge, or discard this patch.