@@ -52,13 +52,13 @@ discard block |
||
| 52 | 52 | * mapped to queries without using sql |
| 53 | 53 | * @since 14.0.0 |
| 54 | 54 | */ |
| 55 | - public function __construct(IDBConnection $db, string $tableName, string $entityClass=null){ |
|
| 55 | + public function __construct(IDBConnection $db, string $tableName, string $entityClass = null) { |
|
| 56 | 56 | $this->db = $db; |
| 57 | 57 | $this->tableName = $tableName; |
| 58 | 58 | |
| 59 | 59 | // if not given set the entity name to the class without the mapper part |
| 60 | 60 | // cache it here for later use since reflection is slow |
| 61 | - if($entityClass === null) { |
|
| 61 | + if ($entityClass === null) { |
|
| 62 | 62 | $this->entityClass = str_replace('Mapper', '', \get_class($this)); |
| 63 | 63 | } else { |
| 64 | 64 | $this->entityClass = $entityClass; |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | $qb->insert($this->tableName); |
| 110 | 110 | |
| 111 | 111 | // build the fields |
| 112 | - foreach($properties as $property => $updated) { |
|
| 112 | + foreach ($properties as $property => $updated) { |
|
| 113 | 113 | $column = $entity->propertyToColumn($property); |
| 114 | - $getter = 'get' . ucfirst($property); |
|
| 114 | + $getter = 'get'.ucfirst($property); |
|
| 115 | 115 | $value = $entity->$getter(); |
| 116 | 116 | |
| 117 | 117 | $qb->setValue($column, $qb->createNamedParameter($value)); |
@@ -119,8 +119,8 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | $qb->execute(); |
| 121 | 121 | |
| 122 | - if($entity->id === null) { |
|
| 123 | - $entity->setId((int)$qb->getLastInsertId()); |
|
| 122 | + if ($entity->id === null) { |
|
| 123 | + $entity->setId((int) $qb->getLastInsertId()); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | return $entity; |
@@ -156,13 +156,13 @@ discard block |
||
| 156 | 156 | public function update(Entity $entity): Entity { |
| 157 | 157 | // if entity wasn't changed it makes no sense to run a db query |
| 158 | 158 | $properties = $entity->getUpdatedFields(); |
| 159 | - if(\count($properties) === 0) { |
|
| 159 | + if (\count($properties) === 0) { |
|
| 160 | 160 | return $entity; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // entity needs an id |
| 164 | 164 | $id = $entity->getId(); |
| 165 | - if($id === null){ |
|
| 165 | + if ($id === null) { |
|
| 166 | 166 | throw new \InvalidArgumentException( |
| 167 | 167 | 'Entity which should be updated has no id'); |
| 168 | 168 | } |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | $qb->update($this->tableName); |
| 177 | 177 | |
| 178 | 178 | // build the fields |
| 179 | - foreach($properties as $property => $updated) { |
|
| 179 | + foreach ($properties as $property => $updated) { |
|
| 180 | 180 | $column = $entity->propertyToColumn($property); |
| 181 | - $getter = 'get' . ucfirst($property); |
|
| 181 | + $getter = 'get'.ucfirst($property); |
|
| 182 | 182 | $value = $entity->$getter(); |
| 183 | 183 | |
| 184 | 184 | $qb->set($column, $qb->createNamedParameter($value)); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $cursor = $query->execute(); |
| 209 | 209 | |
| 210 | 210 | $row = $cursor->fetch(); |
| 211 | - if($row === false) { |
|
| 211 | + if ($row === false) { |
|
| 212 | 212 | $cursor->closeCursor(); |
| 213 | 213 | $msg = $this->buildDebugMessage( |
| 214 | 214 | 'Did expect one result but found none when executing', $query |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | $row2 = $cursor->fetch(); |
| 220 | 220 | $cursor->closeCursor(); |
| 221 | - if($row2 !== false ) { |
|
| 221 | + if ($row2 !== false) { |
|
| 222 | 222 | $msg = $this->buildDebugMessage( |
| 223 | 223 | 'Did not expect more than one result when executing', $query |
| 224 | 224 | ); |
@@ -235,8 +235,8 @@ discard block |
||
| 235 | 235 | * @since 14.0.0 |
| 236 | 236 | */ |
| 237 | 237 | private function buildDebugMessage(string $msg, IQueryBuilder $sql): string { |
| 238 | - return $msg . |
|
| 239 | - ': query "' . $sql->getSQL() . '"; '; |
|
| 238 | + return $msg. |
|
| 239 | + ': query "'.$sql->getSQL().'"; '; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * @since 14.0.0 |
| 250 | 250 | */ |
| 251 | 251 | protected function mapRowToEntity(array $row): Entity { |
| 252 | - return \call_user_func($this->entityClass .'::fromRow', $row); |
|
| 252 | + return \call_user_func($this->entityClass.'::fromRow', $row); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | $entities = []; |
| 267 | 267 | |
| 268 | - while($row = $cursor->fetch()){ |
|
| 268 | + while ($row = $cursor->fetch()) { |
|
| 269 | 269 | $entities[] = $this->mapRowToEntity($row); |
| 270 | 270 | } |
| 271 | 271 | |