Passed
Push — master ( 678d6d...a52660 )
by dima
02:36
created
src/AbstractDataMapper.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * таблица для сущности
24 24
 	 * @var type 
25 25
 	 */
26
-    protected $entityTable;	
26
+	protected $entityTable;	
27 27
 
28 28
 	/**
29 29
 	 * первичный ключ
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 	
99 99
 	abstract protected function setMappingFields();	
100 100
 	
101
-    public function getAdapter() {
102
-        return $this->adapter;
103
-    }
101
+	public function getAdapter() {
102
+		return $this->adapter;
103
+	}
104 104
 
105 105
 	public function setAdapter(QueryBuilderInterface $adapter){
106 106
 		 $this->adapter = $adapter;
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
 	 * @param type $id
124 124
 	 * @return type
125 125
 	 */
126
-    public function findById($id)
127
-    {
126
+	public function findById($id)
127
+	{
128 128
 		$Criteria = (new Specification())->setWhere($this->key , $id);
129 129
 		
130
-        return $this->findBySpecification($Criteria);
131
-    }	
130
+		return $this->findBySpecification($Criteria);
131
+	}	
132 132
 	
133 133
 	/**
134 134
 	 * Сохранение сущности без спобытий
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 	 */
257 257
 	protected function buildEntity(EntityInterface $Entity, array $row){
258 258
 		
259
-        foreach ($this->mapping_fields as $alias => $cfg ) {
259
+		foreach ($this->mapping_fields as $alias => $cfg ) {
260 260
 			
261 261
 			$value = false;
262 262
 			
@@ -299,9 +299,9 @@  discard block
 block discarded – undo
299 299
 			if($value!==false)
300 300
 				$Entity->{$method_set}($value);
301 301
 			
302
-        }
302
+		}
303 303
 				
304
-        return $Entity;		
304
+		return $Entity;		
305 305
 	}	
306 306
 
307 307
 	
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 		
316 316
 		$row = [];
317 317
 
318
-        foreach ($this->mapping_fields as $alias => $cfg ) {
318
+		foreach ($this->mapping_fields as $alias => $cfg ) {
319 319
 			
320 320
 			$field = $cfg['field'];
321 321
 			
@@ -345,9 +345,9 @@  discard block
 block discarded – undo
345 345
 						
346 346
 			$row[$field] = $value;
347 347
 
348
-        }
348
+		}
349 349
 			
350
-        return $row;		
350
+		return $row;		
351 351
 	}	
352 352
 	
353 353
 	/**
@@ -431,9 +431,9 @@  discard block
 block discarded – undo
431 431
 		//получение записей
432 432
 		$res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification);
433 433
 
434
-        if (!$row = $res->row_array()) {
435
-            return null;
436
-        }
434
+		if (!$row = $res->row_array()) {
435
+			return null;
436
+		}
437 437
 		
438 438
 		if($this->result_array===true){
439 439
 			return $row;
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
 		$res = $this->getAdapter()->getResultQuery($this->getEntityTable(),$specification);
483 483
 		
484 484
 		if (!$rows = $res->result_array()) {
485
-            return null;
486
-        }	
485
+			return null;
486
+		}	
487 487
 		
488 488
 		if($this->result_array===true){
489 489
 			return $rows;
Please login to merge, or discard this patch.
Braces   +28 added lines, -27 removed lines patch added patch discarded remove patch
@@ -138,7 +138,9 @@  discard block
 block discarded – undo
138 138
 		
139 139
 		$data = $this->unbuildEntity($Entity);
140 140
 		
141
-		if(method_exists($this, 'onPrepareData' )) $this->onPrepareData( $Entity , $data );
141
+		if(method_exists($this, 'onPrepareData' )) {
142
+			$this->onPrepareData( $Entity , $data );
143
+		}
142 144
 		
143 145
 		$id = $data[$this->getPrimaryKey()];
144 146
 		unset($data[$this->getPrimaryKey()]);		
@@ -174,13 +176,17 @@  discard block
 block discarded – undo
174 176
 	 */
175 177
 	public function save(EntityInterface $Entity)
176 178
 	{
177
-		if(method_exists($this, 'onAfterSave' )) $this->onAfterSave( $Entity );
179
+		if(method_exists($this, 'onAfterSave' )) {
180
+			$this->onAfterSave( $Entity );
181
+		}
178 182
 		
179 183
 		if(!$this->saveWithoutEvents($Entity)){
180 184
 			return false;
181 185
 		}
182 186
 		
183
-		if(method_exists($this, 'onBeforeSave' )) $this->onBeforeSave( $Entity );
187
+		if(method_exists($this, 'onBeforeSave' )) {
188
+			$this->onBeforeSave( $Entity );
189
+		}
184 190
 
185 191
 		return true;
186 192
 	}
@@ -214,8 +220,7 @@  discard block
 block discarded – undo
214 220
 			if(count($rel['relations'])>0){
215 221
 				$this->createListRelationReq($rel['relations'],$rel_list,$obj_parent_link.'get'.$rel['alias'].'()');
216 222
 				$rel_list [$obj_parent_link.$obj_link]= $rel['name'];
217
-			}
218
-			else{
223
+			} else{
219 224
 				$rel_list [$obj_parent_link.$obj_link] = $rel['name'];
220 225
 			}
221 226
 		}
@@ -263,8 +268,7 @@  discard block
 block discarded – undo
263 268
 			//автоопределени формата массива
264 269
 			if(isset($row[$this->key])){
265 270
 				$field = $cfg['field'];
266
-			}
267
-			else{
271
+			} else{
268 272
 				$field = $alias;
269 273
 			}
270 274
 			
@@ -285,19 +289,18 @@  discard block
 block discarded – undo
285 289
 				
286 290
 				if($this->use_joins===true || empty($row[$field])){
287 291
 					$value = $mapper->createEntity($row);
288
-				}
289
-				else{
292
+				} else{
290 293
 					$fkey = isset($cfg['on']) ? $cfg['on'] :$mapper->key;
291 294
 					$value = $mapper->findBySpecification((new Specification)->setWhere($fkey, $row[$field]));
292 295
 				}				
293 296
 				
294
-			}
295
-			elseif(is_string($field) && isset($row[strtolower($field)])){				
297
+			} elseif(is_string($field) && isset($row[strtolower($field)])){				
296 298
 				$value = $row[strtolower($field)];
297 299
 			}
298 300
 						
299
-			if($value!==false)
300
-				$Entity->{$method_set}($value);
301
+			if($value!==false) {
302
+							$Entity->{$method_set}($value);
303
+			}
301 304
 			
302 305
         }
303 306
 				
@@ -328,18 +331,17 @@  discard block
 block discarded – undo
328 331
 			//--------------------------------------------------------------------
329 332
 			if( isset($cfg['unbuild']) && is_object($cfg['unbuild']) ){
330 333
 				$value = call_user_func($cfg['unbuild'], $Entity->{$method_get}() );
331
-			}
332
-			elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){
334
+			} elseif(isset($cfg['relation']) && is_object($Entity->{$method_get}()) ){
333 335
 				
334
-				if(isset($cfg['on']))
335
-					$fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']);
336
-				else
337
-					$fkey = 'id';
336
+				if(isset($cfg['on'])) {
337
+									$fkey = $this->DI->get($cfg['relation'])->getFieldAlias($cfg['on']);
338
+				} else {
339
+									$fkey = 'id';
340
+				}
338 341
 				
339 342
 				$value = $Entity->{$method_get}()->{'get'.$fkey}();
340 343
 				
341
-			}			
342
-			else{
344
+			} else{
343 345
 				$value = $Entity->{$method_get}();
344 346
 			}			
345 347
 						
@@ -357,8 +359,7 @@  discard block
 block discarded – undo
357 359
 		
358 360
 		if(is_string($field)){
359 361
 			$field = ['field'	=>	$field];
360
-		}
361
-		elseif( (is_array($field) && !isset($field['field'])) || empty($field)){
362
+		} elseif( (is_array($field) && !isset($field['field'])) || empty($field)){
362 363
 			$field['field']	= $alias;
363 364
 		}
364 365
 	
@@ -458,8 +459,7 @@  discard block
 block discarded – undo
458 459
 				$delete_key > '' && 
459 460
 				$Entity->getId() > 0){
460 461
 				$result = $this->getAdapter()->update($this->getEntityTable(), [ $delete_key => 1 ], "{$this->getPrimaryKey()} = '{$Entity->getId()}'");
461
-		}
462
-		elseif($Entity->getId() > 0){
462
+		} elseif($Entity->getId() > 0){
463 463
 			
464 464
 			if($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey()."  = ".$Entity->getId())){
465 465
 				if(method_exists($this, 'onBeforeDelete' )){ $result = $this->onBeforeDelete( $Entity );}
@@ -510,8 +510,9 @@  discard block
 block discarded – undo
510 510
 				$this->use_delete === false &&
511 511
 				$this->setSoftDeleteKey()>'' 
512 512
 				&& !isset($specification->getWhere()[$this->setSoftDeleteKey()])
513
-				)
514
-		$specification->setWhere($this->setSoftDeleteKey(),0);
513
+				) {
514
+				$specification->setWhere($this->setSoftDeleteKey(),0);
515
+		}
515 516
 	}
516 517
 	
517 518
 	/**
Please login to merge, or discard this patch.