Passed
Push — master ( 678d6d...a52660 )
by dima
02:36
created
src/AbstractDataMapper.php 1 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.