@@ -65,8 +65,9 @@ discard block |
||
65 | 65 | if (!isset(MapperCache::me()->fullyInstantiated[$class])) { |
66 | 66 | |
67 | 67 | // Check we set ANNOTATION properly in Mapper instance |
68 | - if ($callEnforcer) |
|
69 | - Enforcer::__add(__CLASS__, $class); |
|
68 | + if ($callEnforcer) { |
|
69 | + Enforcer::__add(__CLASS__, $class); |
|
70 | + } |
|
70 | 71 | |
71 | 72 | $self->getAllVariables(); |
72 | 73 | |
@@ -113,10 +114,11 @@ discard block |
||
113 | 114 | if (isset($varValue[Constraint::LOCAL_COLUMN])) { |
114 | 115 | $constraints[$varName] = $varValue; |
115 | 116 | } else { |
116 | - if (isset($varValue[Embedded::NAME])) |
|
117 | - $embedded[$varName] = $varValue; |
|
118 | - else if (isset($varValue[Complex::TYPE])) |
|
119 | - $complex[$varName] = $varValue; |
|
117 | + if (isset($varValue[Embedded::NAME])) { |
|
118 | + $embedded[$varName] = $varValue; |
|
119 | + } else if (isset($varValue[Complex::TYPE])) { |
|
120 | + $complex[$varName] = $varValue; |
|
121 | + } |
|
120 | 122 | } |
121 | 123 | } |
122 | 124 | |
@@ -126,8 +128,9 @@ discard block |
||
126 | 128 | MapperCache::me()->complex[$thisName][$complexName] = $this->$complexName; |
127 | 129 | } |
128 | 130 | // У нас может не быть комплексов |
129 | - if (!isset(MapperCache::me()->complex[$thisName])) |
|
130 | - MapperCache::me()->complex[$thisName] = []; |
|
131 | + if (!isset(MapperCache::me()->complex[$thisName])) { |
|
132 | + MapperCache::me()->complex[$thisName] = []; |
|
133 | + } |
|
131 | 134 | |
132 | 135 | /** ----------------------EMBEDDED------------------------ */ |
133 | 136 | foreach ($embedded as $embeddedName => $embeddedValue) { |
@@ -135,8 +138,9 @@ discard block |
||
135 | 138 | MapperCache::me()->embedded[$thisName][$embeddedName] = $this->$embeddedName; |
136 | 139 | } |
137 | 140 | // У нас может не быть эмбедов |
138 | - if (!isset(MapperCache::me()->embedded[$thisName])) |
|
139 | - MapperCache::me()->embedded[$thisName] = []; |
|
141 | + if (!isset(MapperCache::me()->embedded[$thisName])) { |
|
142 | + MapperCache::me()->embedded[$thisName] = []; |
|
143 | + } |
|
140 | 144 | |
141 | 145 | /** ----------------------COLUMNS------------------------ */ |
142 | 146 | if (!isset(MapperCache::me()->columns[$thisName])) { |
@@ -147,11 +151,13 @@ discard block |
||
147 | 151 | } |
148 | 152 | } |
149 | 153 | // У нас может не быть колонок |
150 | - if (!isset(MapperCache::me()->columns[$thisName])) |
|
151 | - MapperCache::me()->columns[$thisName] = []; |
|
154 | + if (!isset(MapperCache::me()->columns[$thisName])) { |
|
155 | + MapperCache::me()->columns[$thisName] = []; |
|
156 | + } |
|
152 | 157 | |
153 | - if (!isset(MapperCache::me()->baseColumns[$thisName])) |
|
154 | - MapperCache::me()->baseColumns[$thisName] = []; |
|
158 | + if (!isset(MapperCache::me()->baseColumns[$thisName])) { |
|
159 | + MapperCache::me()->baseColumns[$thisName] = []; |
|
160 | + } |
|
155 | 161 | |
156 | 162 | /** ----------------------CONSTRAINTS------------------------ */ |
157 | 163 | $temporaryConstraints = []; |
@@ -164,16 +170,18 @@ discard block |
||
164 | 170 | //$temporaryConstraint->localTable = $this->getTable(); |
165 | 171 | |
166 | 172 | // If we use View - we do not always need to define constraint fields |
167 | - if ($entityClass !== View::class) |
|
168 | - $temporaryConstraint->localColumn = $this->findColumnByOriginName($temporaryConstraint->localColumn); |
|
173 | + if ($entityClass !== View::class) { |
|
174 | + $temporaryConstraint->localColumn = $this->findColumnByOriginName($temporaryConstraint->localColumn); |
|
175 | + } |
|
169 | 176 | |
170 | 177 | $temporaryConstraints[$constraintName] = $temporaryConstraint; |
171 | 178 | } |
172 | 179 | } |
173 | 180 | |
174 | 181 | // У нас может не быть констрейнтов |
175 | - if (!isset(MapperCache::me()->constraints[$thisName])) |
|
176 | - MapperCache::me()->constraints[$thisName] = []; |
|
182 | + if (!isset(MapperCache::me()->constraints[$thisName])) { |
|
183 | + MapperCache::me()->constraints[$thisName] = []; |
|
184 | + } |
|
177 | 185 | |
178 | 186 | MapperCache::me()->allVariables[$thisName] = new MapperVariables($columns, $constraints, $embedded, $complex); |
179 | 187 | |
@@ -205,14 +213,17 @@ discard block |
||
205 | 213 | */ |
206 | 214 | private function checkProperty($varValue, string $varName): void |
207 | 215 | { |
208 | - if (is_null($varValue)) |
|
209 | - throw new EntityException(sprintf("property '\$%s' of %s is null", $varName, get_class($this))); |
|
216 | + if (is_null($varValue)) { |
|
217 | + throw new EntityException(sprintf("property '\$%s' of %s is null", $varName, get_class($this))); |
|
218 | + } |
|
210 | 219 | |
211 | - if (!is_array($varValue)) |
|
212 | - throw new EntityException(sprintf("property '\$%s' of %s is not array", $varName, get_class($this))); |
|
220 | + if (!is_array($varValue)) { |
|
221 | + throw new EntityException(sprintf("property '\$%s' of %s is not array", $varName, get_class($this))); |
|
222 | + } |
|
213 | 223 | |
214 | - if (count($varValue) == 0) |
|
215 | - throw new EntityException(sprintf("property '\$%s' of %s does not have definitions", $varName, get_class($this))); |
|
224 | + if (count($varValue) == 0) { |
|
225 | + throw new EntityException(sprintf("property '\$%s' of %s does not have definitions", $varName, get_class($this))); |
|
226 | + } |
|
216 | 227 | } |
217 | 228 | |
218 | 229 | /** |
@@ -296,8 +307,9 @@ discard block |
||
296 | 307 | { |
297 | 308 | $keys = []; |
298 | 309 | foreach (MapperCache::me()->columns[$this->name()] as $columnName => $column) { |
299 | - if (isset($column->key) and $column->key === true) |
|
300 | - $keys[$columnName] = $column; |
|
310 | + if (isset($column->key) and $column->key === true) { |
|
311 | + $keys[$columnName] = $column; |
|
312 | + } |
|
301 | 313 | } |
302 | 314 | |
303 | 315 | return $keys; |
@@ -331,8 +343,9 @@ discard block |
||
331 | 343 | */ |
332 | 344 | public function __get($name) |
333 | 345 | { |
334 | - if (!property_exists($this, $name)) |
|
335 | - throw new EntityException(sprintf("Can't find property '\$%s' of '%s'", $name, get_class($this))); |
|
346 | + if (!property_exists($this, $name)) { |
|
347 | + throw new EntityException(sprintf("Can't find property '\$%s' of '%s'", $name, get_class($this))); |
|
348 | + } |
|
336 | 349 | |
337 | 350 | return $this->$name; |
338 | 351 | } |
@@ -362,8 +375,9 @@ discard block |
||
362 | 375 | public function getVarNameByColumn(Column $column) |
363 | 376 | { |
364 | 377 | foreach ($this->getOriginFieldNames() as $varName => $originFieldName) { |
365 | - if ($originFieldName == $column->name) |
|
366 | - return $varName; |
|
378 | + if ($originFieldName == $column->name) { |
|
379 | + return $varName; |
|
380 | + } |
|
367 | 381 | } |
368 | 382 | |
369 | 383 | throw new EntityException(sprintf("Seems column '%s' does not belong to this mapper", $column->name)); |
@@ -376,11 +390,12 @@ discard block |
||
376 | 390 | { |
377 | 391 | $thisName = $this->name(); |
378 | 392 | if (!isset(MapperCache::me()->originFieldNames[$thisName])) { |
379 | - if (count($this->getColumns())) |
|
380 | - foreach ($this->getColumns() as $columnName => $column) |
|
393 | + if (count($this->getColumns())) { |
|
394 | + foreach ($this->getColumns() as $columnName => $column) |
|
381 | 395 | MapperCache::me()->originFieldNames[$thisName][$columnName] = $column->name; |
382 | - else |
|
383 | - MapperCache::me()->originFieldNames[$thisName] = []; |
|
396 | + } else { |
|
397 | + MapperCache::me()->originFieldNames[$thisName] = []; |
|
398 | + } |
|
384 | 399 | |
385 | 400 | } |
386 | 401 |
@@ -60,12 +60,14 @@ |
||
60 | 60 | |
61 | 61 | foreach ($mapper->getColumns() as $column) { |
62 | 62 | $table->columns[] = $column; |
63 | - if ($column->key) |
|
64 | - $table->keys[] = $column; |
|
63 | + if ($column->key) { |
|
64 | + $table->keys[] = $column; |
|
65 | + } |
|
65 | 66 | } |
66 | 67 | |
67 | - foreach ($mapper->getConstraints() as $constraint) |
|
68 | - $table->constraints[] = $constraint; |
|
68 | + foreach ($mapper->getConstraints() as $constraint) { |
|
69 | + $table->constraints[] = $constraint; |
|
70 | + } |
|
69 | 71 | |
70 | 72 | return $table; |
71 | 73 | } |
@@ -61,8 +61,9 @@ discard block |
||
61 | 61 | |
62 | 62 | $calledClass = get_class($this); |
63 | 63 | |
64 | - if (!$this instanceof SyntheticEntity) |
|
65 | - Enforcer::__add(__CLASS__, $calledClass); |
|
64 | + if (!$this instanceof SyntheticEntity) { |
|
65 | + Enforcer::__add(__CLASS__, $calledClass); |
|
66 | + } |
|
66 | 67 | |
67 | 68 | try { |
68 | 69 | $map = self::map(); |
@@ -86,8 +87,9 @@ discard block |
||
86 | 87 | |
87 | 88 | // У нас может быть цепочка классов, где какой-то конечный уже не имеет интерфейса OnlyDeclaredPropertiesEntity |
88 | 89 | // соответственно нам надо собрать все переменные всех дочерних классов, даже если они расширяют друг друга |
89 | - if ($this instanceof OnlyDeclaredPropertiesEntity) |
|
90 | - $this->collectDeclarationsOnly(new ReflectionObject($this), $calledClass); |
|
90 | + if ($this instanceof OnlyDeclaredPropertiesEntity) { |
|
91 | + $this->collectDeclarationsOnly(new ReflectionObject($this), $calledClass); |
|
92 | + } |
|
91 | 93 | } |
92 | 94 | |
93 | 95 | if ($this instanceof OnlyDeclaredPropertiesEntity) { |
@@ -102,13 +104,15 @@ discard block |
||
102 | 104 | if ($this instanceof FullEntity or $this instanceof StrictlyFilledEntity) { |
103 | 105 | $checkAgainst = array_merge($map->getColumns(), $map->getComplex(), $map->getEmbedded(), $map->getConstraints()); |
104 | 106 | foreach (get_object_vars($this) as $propertyName => $propertyDefaultValue) { |
105 | - if (!array_key_exists($propertyName, $checkAgainst) && $propertyName != 'rawData') |
|
106 | - throw new EntityException(sprintf("Strict Entity %s has unmapped property '%s'", $calledClass, $propertyName)); |
|
107 | + if (!array_key_exists($propertyName, $checkAgainst) && $propertyName != 'rawData') { |
|
108 | + throw new EntityException(sprintf("Strict Entity %s has unmapped property '%s'", $calledClass, $propertyName)); |
|
109 | + } |
|
107 | 110 | } |
108 | 111 | } |
109 | 112 | |
110 | - if (is_null($this->rawData)) |
|
111 | - return; |
|
113 | + if (is_null($this->rawData)) { |
|
114 | + return; |
|
115 | + } |
|
112 | 116 | |
113 | 117 | // Если мы определяем класс с интерфейсом OnlyDeclaredPropertiesEntity и экстендим его |
114 | 118 | // то по сути мы не можем знать какие переменные классам нам обязательны к обработке. |
@@ -116,8 +120,9 @@ discard block |
||
116 | 120 | //if($this instanceof OnlyDeclaredPropertiesEntity and !$reflectionObject->isFinal()) |
117 | 121 | // throw new EntityException("Class " . $reflectionObject->getParentClass()->getShortName() . " which implements OnlyDeclaredPropertiesEntity interface must be final"); |
118 | 122 | |
119 | - if ($currentLevel <= $maxLevels) |
|
120 | - $this->setModelData($map, $maxLevels, $currentLevel); |
|
123 | + if ($currentLevel <= $maxLevels) { |
|
124 | + $this->setModelData($map, $maxLevels, $currentLevel); |
|
125 | + } |
|
121 | 126 | } |
122 | 127 | |
123 | 128 | /** |
@@ -132,17 +137,19 @@ discard block |
||
132 | 137 | /** @var Mapper $mapClass */ |
133 | 138 | $mapClass = $calledClass . Mapper::POSTFIX; |
134 | 139 | |
135 | - if (!class_exists($mapClass, false)) |
|
136 | - throw new EntityException(sprintf("Class %s does not have Map definition", $calledClass)); |
|
140 | + if (!class_exists($mapClass, false)) { |
|
141 | + throw new EntityException(sprintf("Class %s does not have Map definition", $calledClass)); |
|
142 | + } |
|
137 | 143 | |
138 | 144 | /** @noinspection PhpUnhandledExceptionInspection */ |
139 | 145 | $reflection = new ReflectionClass($calledClass); |
140 | 146 | $interfaces = $reflection->getInterfaces(); |
141 | 147 | |
142 | - if (isset($interfaces[SyntheticEntity::class])) |
|
143 | - return $mapClass::meWithoutEnforcer(); |
|
144 | - else |
|
145 | - return $mapClass::me(); |
|
148 | + if (isset($interfaces[SyntheticEntity::class])) { |
|
149 | + return $mapClass::meWithoutEnforcer(); |
|
150 | + } else { |
|
151 | + return $mapClass::me(); |
|
152 | + } |
|
146 | 153 | } |
147 | 154 | |
148 | 155 | /** |
@@ -156,15 +163,17 @@ discard block |
||
156 | 163 | |
157 | 164 | $declaringClass = $property->getDeclaringClass(); |
158 | 165 | |
159 | - if ($declaringClass->name == $calledClass || $declaringClass->name == $parentClass) |
|
160 | - EntityCache::$mapCache[$calledClass][EntityCache::DECLARED_PROPERTIES][$property->name] = true; |
|
166 | + if ($declaringClass->name == $calledClass || $declaringClass->name == $parentClass) { |
|
167 | + EntityCache::$mapCache[$calledClass][EntityCache::DECLARED_PROPERTIES][$property->name] = true; |
|
168 | + } |
|
161 | 169 | } |
162 | 170 | |
163 | 171 | $parentClass = $reflectionObject->getParentClass(); |
164 | 172 | $parentInterfaces = $parentClass->getInterfaces(); |
165 | 173 | |
166 | - if (isset($parentInterfaces[OnlyDeclaredPropertiesEntity::class])) |
|
167 | - $this->collectDeclarationsOnly($parentClass, $calledClass, $parentClass->name); |
|
174 | + if (isset($parentInterfaces[OnlyDeclaredPropertiesEntity::class])) { |
|
175 | + $this->collectDeclarationsOnly($parentClass, $calledClass, $parentClass->name); |
|
176 | + } |
|
168 | 177 | |
169 | 178 | /** If we have defined declaredProperties key, we must exclude some keys from reverseMap and arrayMap */ |
170 | 179 | if (isset(EntityCache::$mapCache[$calledClass][EntityCache::DECLARED_PROPERTIES])) { |
@@ -243,14 +252,16 @@ discard block |
||
243 | 252 | foreach ($this->rawData as $originColumnName => &$columnValue) { |
244 | 253 | |
245 | 254 | /** process only if Entity class has such field declaration */ |
246 | - if (!isset($fieldMapping[$originColumnName])) |
|
247 | - continue; |
|
255 | + if (!isset($fieldMapping[$originColumnName])) { |
|
256 | + continue; |
|
257 | + } |
|
248 | 258 | |
249 | 259 | /** @var string $property name of field declaration in Entity class */ |
250 | 260 | $property = $fieldMapping[$originColumnName]; |
251 | 261 | |
252 | - if (!property_exists($this, $property)) |
|
253 | - continue; |
|
262 | + if (!property_exists($this, $property)) { |
|
263 | + continue; |
|
264 | + } |
|
254 | 265 | |
255 | 266 | /** Note: Function names are case-insensitive, though it is usually good form to call functions as they appear in their declaration. */ |
256 | 267 | $setterMethod = "set{$property}"; |
@@ -258,8 +269,9 @@ discard block |
||
258 | 269 | /** @var Column $fieldDefinition */ |
259 | 270 | $fieldDefinition = $mapper->$property; |
260 | 271 | |
261 | - if (is_null($columnValue) and $fieldDefinition->nullable === false) |
|
262 | - throw new EntityException(sprintf("Column %s of %s shouldn't accept null values according Mapper definition", $originColumnName, $calledClass)); |
|
272 | + if (is_null($columnValue) and $fieldDefinition->nullable === false) { |
|
273 | + throw new EntityException(sprintf("Column %s of %s shouldn't accept null values according Mapper definition", $originColumnName, $calledClass)); |
|
274 | + } |
|
263 | 275 | |
264 | 276 | /** We can define setter method for field definition in Entity class, so let's check it first */ |
265 | 277 | if (method_exists($this, $setterMethod)) { |
@@ -274,8 +286,9 @@ discard block |
||
274 | 286 | * But some times we need to have default value for column in case of $rowData has null value |
275 | 287 | * In this case we should not override default value if $columnValue is null |
276 | 288 | */ |
277 | - if (!isset($this->$property) and isset($columnValue)) |
|
278 | - $this->$property = &$columnValue; |
|
289 | + if (!isset($this->$property) and isset($columnValue)) { |
|
290 | + $this->$property = &$columnValue; |
|
291 | + } |
|
279 | 292 | } |
280 | 293 | } |
281 | 294 | } |
@@ -295,8 +308,9 @@ discard block |
||
295 | 308 | $embeddings = MapperCache::me()->embedded[$map->name()]; |
296 | 309 | $missingColumns = []; |
297 | 310 | foreach ($embeddings as $embedding) { |
298 | - if ($embedding->name !== false and !array_key_exists($embedding->name, $this->rawData)) |
|
299 | - $missingColumns[] = $embedding->name; |
|
311 | + if ($embedding->name !== false and !array_key_exists($embedding->name, $this->rawData)) { |
|
312 | + $missingColumns[] = $embedding->name; |
|
313 | + } |
|
300 | 314 | } |
301 | 315 | if (count($missingColumns) > 0) { |
302 | 316 | throw new EntityException(sprintf("Seems you forgot to select columns for FullEntity or StrictlyFilledEntity '%s': %s", |
@@ -328,8 +342,9 @@ discard block |
||
328 | 342 | if ($embeddedValue->isIterable) { |
329 | 343 | $iterables = []; |
330 | 344 | if (isset($this->rawData[$embeddedValue->name]) and !is_null($this->rawData[$embeddedValue->name])) { |
331 | - foreach ($this->rawData[$embeddedValue->name] as $value) |
|
332 | - $iterables[] = new $embeddedValue->entityClass($value, $maxLevels, $currentLevel); |
|
345 | + foreach ($this->rawData[$embeddedValue->name] as $value) { |
|
346 | + $iterables[] = new $embeddedValue->entityClass($value, $maxLevels, $currentLevel); |
|
347 | + } |
|
333 | 348 | |
334 | 349 | $this->$embeddedName = $iterables; |
335 | 350 | } |
@@ -356,10 +371,11 @@ discard block |
||
356 | 371 | //if (!property_exists($this, $complexName) or isset(EntityCache::$mapCache[get_called_class()][EntityCache::UNSET_PROPERTIES][$complexName])) |
357 | 372 | // continue; |
358 | 373 | |
359 | - if ($currentLevel <= $maxLevels) |
|
360 | - $this->$complexName = new $complexValue->complexClass($this->rawData, $maxLevels, $currentLevel); |
|
361 | - else |
|
362 | - unset($this->$complexName); |
|
374 | + if ($currentLevel <= $maxLevels) { |
|
375 | + $this->$complexName = new $complexValue->complexClass($this->rawData, $maxLevels, $currentLevel); |
|
376 | + } else { |
|
377 | + unset($this->$complexName); |
|
378 | + } |
|
363 | 379 | } |
364 | 380 | } |
365 | 381 |
@@ -93,7 +93,8 @@ |
||
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | - if (is_null($this->name)) |
|
97 | - throw new EntityException(sprintf("columns not set: %s. Check that Embedded and Complex fields are protected type.", json_encode($columnNameOrArray))); |
|
96 | + if (is_null($this->name)) { |
|
97 | + throw new EntityException(sprintf("columns not set: %s. Check that Embedded and Complex fields are protected type.", json_encode($columnNameOrArray))); |
|
98 | + } |
|
98 | 99 | } |
99 | 100 | } |
@@ -73,7 +73,8 @@ |
||
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | - if (is_null($this->name)) |
|
77 | - throw new EntityException("Embedded name not set"); |
|
76 | + if (is_null($this->name)) { |
|
77 | + throw new EntityException("Embedded name not set"); |
|
78 | + } |
|
78 | 79 | } |
79 | 80 | } |
@@ -56,7 +56,8 @@ |
||
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | - if (is_null($this->complexClass)) |
|
60 | - throw new EntityException("Complex className not set"); |
|
59 | + if (is_null($this->complexClass)) { |
|
60 | + throw new EntityException("Complex className not set"); |
|
61 | + } |
|
61 | 62 | } |
62 | 63 | } |
@@ -65,8 +65,9 @@ |
||
65 | 65 | */ |
66 | 66 | public static function convertBoolVar($variable): ?bool |
67 | 67 | { |
68 | - if (is_string($variable)) |
|
69 | - $variable = strtolower(trim($variable)); |
|
68 | + if (is_string($variable)) { |
|
69 | + $variable = strtolower(trim($variable)); |
|
70 | + } |
|
70 | 71 | |
71 | 72 | switch ($variable) { |
72 | 73 | case 't': |