Passed
Push — master ( e4d4e4...c57a16 )
by Morris
45:48 queued 32:01
created
lib/public/AppFramework/Db/QBMapper.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 			$type = $this->getParameterTypeForProperty($entity, $property);
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 
121 121
 		$qb->execute();
122 122
 
123
-		if($entity->id === null) {
124
-			$entity->setId((int)$qb->getLastInsertId());
123
+		if ($entity->id === null) {
124
+			$entity->setId((int) $qb->getLastInsertId());
125 125
 		}
126 126
 
127 127
 		return $entity;
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
 	public function update(Entity $entity): Entity {
158 158
 		// if entity wasn't changed it makes no sense to run a db query
159 159
 		$properties = $entity->getUpdatedFields();
160
-		if(\count($properties) === 0) {
160
+		if (\count($properties) === 0) {
161 161
 			return $entity;
162 162
 		}
163 163
 
164 164
 		// entity needs an id
165 165
 		$id = $entity->getId();
166
-		if($id === null){
166
+		if ($id === null) {
167 167
 			throw new \InvalidArgumentException(
168 168
 				'Entity which should be updated has no id');
169 169
 		}
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
 		$qb->update($this->tableName);
178 178
 
179 179
 		// build the fields
180
-		foreach($properties as $property => $updated) {
180
+		foreach ($properties as $property => $updated) {
181 181
 			$column = $entity->propertyToColumn($property);
182
-			$getter = 'get' . ucfirst($property);
182
+			$getter = 'get'.ucfirst($property);
183 183
 			$value = $entity->$getter();
184 184
 
185 185
 			$type = $this->getParameterTypeForProperty($entity, $property);
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
 	protected function getParameterTypeForProperty(Entity $entity, string $property): int {
207 207
 		$types = $entity->getFieldTypes();
208 208
 
209
-		if(!isset($types[ $property ])) {
209
+		if (!isset($types[$property])) {
210 210
 			return IQueryBuilder::PARAM_STR;
211 211
 		}
212 212
 
213
-		switch($types[ $property ]) {
213
+		switch ($types[$property]) {
214 214
 			case 'int':
215 215
 			case 'integer':
216 216
 				return IQueryBuilder::PARAM_INT;
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 		$cursor = $query->execute();
241 241
 
242 242
 		$row = $cursor->fetch();
243
-		if($row === false) {
243
+		if ($row === false) {
244 244
 			$cursor->closeCursor();
245 245
 			$msg = $this->buildDebugMessage(
246 246
 				'Did expect one result but found none when executing', $query
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 
251 251
 		$row2 = $cursor->fetch();
252 252
 		$cursor->closeCursor();
253
-		if($row2 !== false ) {
253
+		if ($row2 !== false) {
254 254
 			$msg = $this->buildDebugMessage(
255 255
 				'Did not expect more than one result when executing', $query
256 256
 			);
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 	 * @since 14.0.0
268 268
 	 */
269 269
 	private function buildDebugMessage(string $msg, IQueryBuilder $sql): string {
270
-		return $msg .
271
-			': query "' . $sql->getSQL() . '"; ';
270
+		return $msg.
271
+			': query "'.$sql->getSQL().'"; ';
272 272
 	}
273 273
 
274 274
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @since 14.0.0
282 282
 	 */
283 283
 	protected function mapRowToEntity(array $row): Entity {
284
-		return \call_user_func($this->entityClass .'::fromRow', $row);
284
+		return \call_user_func($this->entityClass.'::fromRow', $row);
285 285
 	}
286 286
 
287 287
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 
298 298
 		$entities = [];
299 299
 
300
-		while($row = $cursor->fetch()){
300
+		while ($row = $cursor->fetch()) {
301 301
 			$entities[] = $this->mapRowToEntity($row);
302 302
 		}
303 303
 
Please login to merge, or discard this patch.