Passed
Push — master ( fbb2a0...5a733a )
by dima
04:06
created
src/AbstractDataMapper.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	 * таблица для сущности
20 20
 	 * @var type 
21 21
 	 */
22
-    protected $entityTable;	
22
+	protected $entityTable;	
23 23
 
24 24
 	/**
25 25
 	 * первичный ключ
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 
89 89
 	abstract protected function setMappingFields();	
90 90
 	
91
-    public function getAdapter() {
92
-        return $this->adapter;
93
-    }
91
+	public function getAdapter() {
92
+		return $this->adapter;
93
+	}
94 94
 
95 95
 	public function setAdapter(QueryBuilderInterface $adapter){
96 96
 		 $this->adapter = $adapter;
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
 	}	
110 110
 
111 111
 
112
-    public function findById($id)
113
-    {
112
+	public function findById($id)
113
+	{
114 114
 		$Criteria = (new Specification())->setWhere($this->key , $id);
115 115
 		
116
-        return $this->findBySpecification($Criteria);
117
-    }	
116
+		return $this->findBySpecification($Criteria);
117
+	}	
118 118
 	
119 119
 	/**
120 120
 	 * Cохранение сущности
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	 */
211 211
 	protected function buildEntity(EntityInterface $Entity, array $row){
212 212
 		
213
-        foreach ($this->mapping_fields as $alias => $cfg ) {
213
+		foreach ($this->mapping_fields as $alias => $cfg ) {
214 214
 			
215 215
 			$value = false;
216 216
 			
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
 			if($value!==false)
248 248
 				$Entity->{$method_set}($value);
249 249
 			
250
-        }
250
+		}
251 251
 		
252
-        return $Entity;		
252
+		return $Entity;		
253 253
 	}	
254 254
 
255 255
 	
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 		
264 264
 		$row = [];
265 265
 
266
-        foreach ($this->mapping_fields as $alias => $cfg ) {
266
+		foreach ($this->mapping_fields as $alias => $cfg ) {
267 267
 			
268 268
 			$field = $cfg['field'];
269 269
 			
@@ -293,9 +293,9 @@  discard block
 block discarded – undo
293 293
 						
294 294
 			$row[$field] = $value;
295 295
 
296
-        }
296
+		}
297 297
 
298
-        return $row;		
298
+		return $row;		
299 299
 	}	
300 300
 	
301 301
 	/**
@@ -367,10 +367,10 @@  discard block
 block discarded – undo
367 367
 		//получение записей
368 368
 		$res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification);
369 369
 
370
-        if (!$row = $res->row_array()) {
371
-            return null;
372
-        }
373
-        return $this->createEntity($row);				
370
+		if (!$row = $res->row_array()) {
371
+			return null;
372
+		}
373
+		return $this->createEntity($row);				
374 374
 	}
375 375
 	
376 376
 	/**
@@ -412,8 +412,8 @@  discard block
 block discarded – undo
412 412
 		$res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification);
413 413
 		
414 414
 		if (!$rows = $res->result_array()) {
415
-            return null;
416
-        }	
415
+			return null;
416
+		}	
417 417
 		
418 418
 		foreach($rows as $k =>  $row){
419 419
 			$rows[$k] = $this->createEntity($row);
Please login to merge, or discard this patch.
Braces   +23 added lines, -22 removed lines patch added patch discarded remove patch
@@ -126,7 +126,9 @@  discard block
 block discarded – undo
126 126
 		$data = $this->unbuildEntity($Entity);
127 127
 		
128 128
 		//protected function onAfterSave(\SimpleORM\EntityInterface $Entity, &$data)
129
-		if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity, $data );
129
+		if(method_exists($this, 'onAfterSave' )) {
130
+			$this->onAfterSave( $Entity, $data );
131
+		}
130 132
 		
131 133
 		$id = $data[$this->getPrimaryKey()];
132 134
 		unset($data[$this->getPrimaryKey()]);		
@@ -153,7 +155,9 @@  discard block
 block discarded – undo
153 155
 
154 156
 		}		
155 157
 		
156
-		if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity );
158
+		if(method_exists($this, 'onBeforeSave' )) {
159
+			$this->onBeforeSave( $Entity );
160
+		}
157 161
 
158 162
 		
159 163
 		return true;
@@ -233,19 +237,18 @@  discard block
 block discarded – undo
233 237
 				
234 238
 				if($this->use_joins===true){
235 239
 					$value = $mapper->createEntity($row);
236
-				}
237
-				else{
240
+				} else{
238 241
 					$fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key;
239 242
 					$value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field]));
240 243
 				}				
241 244
 				
242
-			}
243
-			elseif(is_string($field) && isset($row[strtolower($field)])){
245
+			} elseif(is_string($field) && isset($row[strtolower($field)])){
244 246
 				$value = $row[strtolower($field)];
245 247
 			}
246 248
 			
247
-			if($value!==false)
248
-				$Entity->{$method_set}($value);
249
+			if($value!==false) {
250
+							$Entity->{$method_set}($value);
251
+			}
249 252
 			
250 253
         }
251 254
 		
@@ -276,18 +279,17 @@  discard block
 block discarded – undo
276 279
 			//--------------------------------------------------------------------
277 280
 			if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){
278 281
 				$value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() );
279
-			}
280
-			elseif(isset($cfg['relation'])){
282
+			} elseif(isset($cfg['relation'])){
281 283
 				
282
-				if(isset($cfg['on']))
283
-					$fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']);
284
-				else
285
-					$fkey = 'id';
284
+				if(isset($cfg['on'])) {
285
+									$fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']);
286
+				} else {
287
+									$fkey = 'id';
288
+				}
286 289
 				
287 290
 				$value = $Entity->{$method_get}()->{'get'.$fkey}();
288 291
 				
289
-			}			
290
-			else{
292
+			} else{
291 293
 				$value = $Entity->{$method_get}();
292 294
 			}			
293 295
 						
@@ -305,8 +307,7 @@  discard block
 block discarded – undo
305 307
 		
306 308
 		if(is_string($field)){
307 309
 			$field = ['field'	=>	$field];
308
-		}
309
-		elseif( (is_array($field) && !isset($field['field'])) || empty($field)){
310
+		} elseif( (is_array($field) && !isset($field['field'])) || empty($field)){
310 311
 			$field['field']	= $alias;
311 312
 		}
312 313
 	
@@ -388,8 +389,7 @@  discard block
 block discarded – undo
388 389
 				$delete_key > '' && 
389 390
 				$Entity->getId() > 0){
390 391
 				$result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'");
391
-		}
392
-		elseif($Entity->getId() > 0){
392
+		} elseif($Entity->getId() > 0){
393 393
 			
394 394
 			if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()."  = ".$Entity->getId())){
395 395
 				if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );}
@@ -436,8 +436,9 @@  discard block
 block discarded – undo
436 436
 				$this->use_delete === false &&
437 437
 				$this->setSoftDeleteKey()>'' 
438 438
 				&& !isset($specification->getWhere()[$this->setSoftDeleteKey()])
439
-				)
440
-		$specification->setWhere($this->setSoftDeleteKey(),0);
439
+				) {
440
+				$specification->setWhere($this->setSoftDeleteKey(),0);
441
+		}
441 442
 	}
442 443
 	
443 444
 	/**
Please login to merge, or discard this patch.