@@ -30,16 +30,16 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function __construct(array $conditions = [], string $sortField = null, string $sortDir = null, int $offset = null, int $limit = null) |
| 32 | 32 | { |
| 33 | - if($conditions = $this->parseConditionsArg($conditions)) { |
|
| 33 | + if ($conditions = $this->parseConditionsArg($conditions)) { |
|
| 34 | 34 | $this->conditions = $conditions; |
| 35 | 35 | } |
| 36 | - if($sortField && $sortDir) { |
|
| 36 | + if ($sortField && $sortDir) { |
|
| 37 | 37 | $this->addSort($sortField, $sortDir); |
| 38 | 38 | } |
| 39 | - if($offset) { |
|
| 39 | + if ($offset) { |
|
| 40 | 40 | $this->offset($offset); |
| 41 | 41 | } |
| 42 | - if($limit) { |
|
| 42 | + if ($limit) { |
|
| 43 | 43 | $this->limit($limit); |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -218,16 +218,16 @@ discard block |
||
| 218 | 218 | protected function parseConditionsArg($conditions) |
| 219 | 219 | { |
| 220 | 220 | $result = []; |
| 221 | - if(is_array($conditions)) { |
|
| 221 | + if (is_array($conditions)) { |
|
| 222 | 222 | foreach ($conditions as $k => $v) { |
| 223 | - if(is_numeric($k) && is_array($v)) { |
|
| 223 | + if (is_numeric($k) && is_array($v)) { |
|
| 224 | 224 | $result[] = $v; |
| 225 | 225 | } |
| 226 | - else if(is_string($k) && $v) { |
|
| 227 | - if(is_scalar($v)) { |
|
| 226 | + else if (is_string($k) && $v) { |
|
| 227 | + if (is_scalar($v)) { |
|
| 228 | 228 | $result[] = [self::EQUALS, $k, $v]; |
| 229 | 229 | } |
| 230 | - else if(is_array($v)) { |
|
| 230 | + else if (is_array($v)) { |
|
| 231 | 231 | $result[] = [self::IN, $k, $v]; |
| 232 | 232 | } |
| 233 | 233 | } |
@@ -222,12 +222,10 @@ |
||
| 222 | 222 | foreach ($conditions as $k => $v) { |
| 223 | 223 | if(is_numeric($k) && is_array($v)) { |
| 224 | 224 | $result[] = $v; |
| 225 | - } |
|
| 226 | - else if(is_string($k) && $v) { |
|
| 225 | + } else if(is_string($k) && $v) { |
|
| 227 | 226 | if(is_scalar($v)) { |
| 228 | 227 | $result[] = [self::EQUALS, $k, $v]; |
| 229 | - } |
|
| 230 | - else if(is_array($v)) { |
|
| 228 | + } else if(is_array($v)) { |
|
| 231 | 229 | $result[] = [self::IN, $k, $v]; |
| 232 | 230 | } |
| 233 | 231 | } |
@@ -10,11 +10,11 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | public function parse(QueryBuilder $queryBuilder, Condition $condition = null) |
| 12 | 12 | { |
| 13 | - if(!$condition) { |
|
| 13 | + if (!$condition) { |
|
| 14 | 14 | return; |
| 15 | 15 | } |
| 16 | 16 | foreach ($condition->getConditions() as $cond) { |
| 17 | - if(is_array($cond)) { |
|
| 17 | + if (is_array($cond)) { |
|
| 18 | 18 | $cond = array_values($cond); |
| 19 | 19 | $type = array_shift($cond); |
| 20 | 20 | switch ($type) { |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $queryBuilder->andWhere("{$cond[0]} LIKE " . $queryBuilder->createNamedParameter($value)); |
| 48 | 48 | break; |
| 49 | 49 | case Condition::IN: |
| 50 | - if($cond[1]) { |
|
| 50 | + if ($cond[1]) { |
|
| 51 | 51 | $isNumeric = $cond[2]; |
| 52 | 52 | $sql = ''; |
| 53 | 53 | foreach ($cond[1] as $v) { |
@@ -67,11 +67,11 @@ discard block |
||
| 67 | 67 | $queryBuilder->orderBy($field, $direction == SORT_DESC ? 'desc' : 'asc'); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if($offset = $condition->getOffset()) { |
|
| 70 | + if ($offset = $condition->getOffset()) { |
|
| 71 | 71 | $queryBuilder->setFirstResult($offset); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if($limit = $condition->getLimit()) { |
|
| 74 | + if ($limit = $condition->getLimit()) { |
|
| 75 | 75 | $queryBuilder->setMaxResults($limit); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -54,8 +54,7 @@ |
||
| 54 | 54 | $sql .= ($isNumeric ? (float)$v : $queryBuilder->createNamedParameter($v)) . ','; |
| 55 | 55 | } |
| 56 | 56 | $queryBuilder->andWhere("{$cond[0]} IN (" . rtrim($sql, ',') . ")"); |
| 57 | - } |
|
| 58 | - else { |
|
| 57 | + } else { |
|
| 59 | 58 | $queryBuilder->andWhere('1 = 2'); // IN empty array is always false |
| 60 | 59 | } |
| 61 | 60 | break; |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | ) |
| 34 | 34 | { |
| 35 | 35 | parent::__construct($container); |
| 36 | - if($objectClass !== null) { |
|
| 36 | + if ($objectClass !== null) { |
|
| 37 | 37 | $this->objectClass = $objectClass; |
| 38 | 38 | } |
| 39 | 39 | $this->hydrator = $hydrator; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | { |
| 57 | 57 | $result = null; |
| 58 | 58 | $select = $this->selectQuery()->where('t1 = :id')->setParameter(':id', $id); |
| 59 | - if($row = $select->execute()->fetch()) { |
|
| 59 | + if ($row = $select->execute()->fetch()) { |
|
| 60 | 60 | $this->unserializeFields($row); |
| 61 | 61 | $result = $this->factory->createFromData($row); |
| 62 | 62 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $result = null; |
| 74 | 74 | $select = $this->selectQuery($condition); |
| 75 | - if($row = $select->execute()->fetch()) { |
|
| 75 | + if ($row = $select->execute()->fetch()) { |
|
| 76 | 76 | $this->unserializeFields($row); |
| 77 | 77 | $result = $this->factory->createFromData($row); |
| 78 | 78 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | { |
| 89 | 89 | $result = []; |
| 90 | 90 | $select = $this->selectQuery($condition); |
| 91 | - if($rows = $select->execute()->fetchAll(\PDO::FETCH_ASSOC)) { |
|
| 91 | + if ($rows = $select->execute()->fetchAll(\PDO::FETCH_ASSOC)) { |
|
| 92 | 92 | foreach ($rows as $row) { |
| 93 | 93 | $this->unserializeFields($row); |
| 94 | 94 | /** @var AbstractEntity $entity */ |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | $data = $this->hydrator->extract($item); |
| 119 | 119 | $this->beforeDataSave($data); |
| 120 | 120 | $this->serializeFields($data); |
| 121 | - if($id = $item->getId()) { |
|
| 121 | + if ($id = $item->getId()) { |
|
| 122 | 122 | $this->db->update($this->table, $data, ['id' => $id]); |
| 123 | 123 | } |
| 124 | 124 | else { |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | private function serializeFields(&$data) |
| 163 | 163 | { |
| 164 | 164 | foreach ($this->serializeFields as $field) { |
| 165 | - if(isset($data[$field])) { |
|
| 165 | + if (isset($data[$field])) { |
|
| 166 | 166 | $data[$field] = $this->serializeStrategy == self::SERIALIZE_STRATEGY_JSON |
| 167 | 167 | ? json_encode($data[$field]) |
| 168 | 168 | : serialize($data[$field]); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | private function unserializeFields(&$row) |
| 177 | 177 | { |
| 178 | 178 | foreach ($this->serializeFields as $field) { |
| 179 | - if(isset($row[$field])) { |
|
| 179 | + if (isset($row[$field])) { |
|
| 180 | 180 | $row[$field] = $this->serializeStrategy == self::SERIALIZE_STRATEGY_JSON |
| 181 | 181 | ? json_decode($row[$field], true) |
| 182 | 182 | : unserialize($row[$field]); |
@@ -120,8 +120,7 @@ |
||
| 120 | 120 | $this->serializeFields($data); |
| 121 | 121 | if($id = $item->getId()) { |
| 122 | 122 | $this->db->update($this->table, $data, ['id' => $id]); |
| 123 | - } |
|
| 124 | - else { |
|
| 123 | + } else { |
|
| 125 | 124 | unset($data['id']); |
| 126 | 125 | $this->db->insert($this->table, $data); |
| 127 | 126 | $item->setId($this->db->lastInsertId()); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | public function hydrate(array $data, $objectOrClass, $map = []) |
| 21 | 21 | { |
| 22 | - if(is_object($objectOrClass)) { |
|
| 22 | + if (is_object($objectOrClass)) { |
|
| 23 | 23 | $object = $objectOrClass; |
| 24 | 24 | $reflection = $this->getReflection(get_class($object)); |
| 25 | 25 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $object = $reflection->newInstanceWithoutConstructor(); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - if(!$map) { |
|
| 31 | + if (!$map) { |
|
| 32 | 32 | $map = array_keys($data); |
| 33 | 33 | $map = array_combine($map, $map); |
| 34 | 34 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $className = get_class($object); |
| 58 | 58 | $reflection = $this->getReflection($className); |
| 59 | 59 | |
| 60 | - if(!$map) { |
|
| 60 | + if (!$map) { |
|
| 61 | 61 | $propertyList = $this->getReflectionPropertyList($className); |
| 62 | 62 | $map = array_combine($propertyList, $propertyList); |
| 63 | 63 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | protected function getReflectionPropertyList($className) |
| 92 | 92 | { |
| 93 | - if(!isset($this->reflectionsPropertyList[$className])) { |
|
| 93 | + if (!isset($this->reflectionsPropertyList[$className])) { |
|
| 94 | 94 | $this->reflectionsPropertyList[$className] = []; |
| 95 | 95 | foreach ($this->getReflection($className)->getProperties() as $property) { |
| 96 | 96 | $this->reflectionsPropertyList[$className][] = $property->getName(); |
@@ -22,8 +22,7 @@ |
||
| 22 | 22 | if(is_object($objectOrClass)) { |
| 23 | 23 | $object = $objectOrClass; |
| 24 | 24 | $reflection = $this->getReflection(get_class($object)); |
| 25 | - } |
|
| 26 | - else { |
|
| 25 | + } else { |
|
| 27 | 26 | $reflection = $this->getReflection($objectOrClass); |
| 28 | 27 | $object = $reflection->newInstanceWithoutConstructor(); |
| 29 | 28 | } |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function get($id) |
| 30 | 30 | { |
| 31 | - if(!$this->container) { |
|
| 31 | + if (!$this->container) { |
|
| 32 | 32 | throw new ContainerException('Container not injected'); |
| 33 | 33 | } |
| 34 | - if(method_exists($this->container, 'get')) { |
|
| 34 | + if (method_exists($this->container, 'get')) { |
|
| 35 | 35 | return $this->container->get($id); |
| 36 | 36 | } |
| 37 | 37 | else { |
@@ -46,10 +46,10 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function has($id) |
| 48 | 48 | { |
| 49 | - if(!$this->container) { |
|
| 49 | + if (!$this->container) { |
|
| 50 | 50 | throw new ContainerException('Container not injected'); |
| 51 | 51 | } |
| 52 | - if(method_exists($this->container, 'has')) { |
|
| 52 | + if (method_exists($this->container, 'has')) { |
|
| 53 | 53 | return $this->container->has($id); |
| 54 | 54 | } |
| 55 | 55 | else { |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function make($id) |
| 66 | 66 | { |
| 67 | - if(!$this->container) { |
|
| 67 | + if (!$this->container) { |
|
| 68 | 68 | throw new ContainerException('Container not injected'); |
| 69 | 69 | } |
| 70 | - if(method_exists($this->container, 'make')) { |
|
| 70 | + if (method_exists($this->container, 'make')) { |
|
| 71 | 71 | return $this->container->make($id); |
| 72 | 72 | } |
| 73 | 73 | else { |
@@ -33,8 +33,7 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | if(method_exists($this->container, 'get')) { |
| 35 | 35 | return $this->container->get($id); |
| 36 | - } |
|
| 37 | - else { |
|
| 36 | + } else { |
|
| 38 | 37 | throw new ContainerException('Container method not found: get'); |
| 39 | 38 | } |
| 40 | 39 | } |
@@ -51,8 +50,7 @@ discard block |
||
| 51 | 50 | } |
| 52 | 51 | if(method_exists($this->container, 'has')) { |
| 53 | 52 | return $this->container->has($id); |
| 54 | - } |
|
| 55 | - else { |
|
| 53 | + } else { |
|
| 56 | 54 | throw new ContainerException('Container method not found: has'); |
| 57 | 55 | } |
| 58 | 56 | } |
@@ -69,8 +67,7 @@ discard block |
||
| 69 | 67 | } |
| 70 | 68 | if(method_exists($this->container, 'make')) { |
| 71 | 69 | return $this->container->make($id); |
| 72 | - } |
|
| 73 | - else { |
|
| 70 | + } else { |
|
| 74 | 71 | throw new ContainerException('Container method not found: make'); |
| 75 | 72 | } |
| 76 | 73 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | public function addError($code, $error) |
| 18 | 18 | { |
| 19 | - if(!isset($this->_errors[$code])) { |
|
| 19 | + if (!isset($this->_errors[$code])) { |
|
| 20 | 20 | $this->_errors[$code] = []; |
| 21 | 21 | } |
| 22 | 22 | $this->_errors[$code][] = $error; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function getErrors($code = null) |
| 39 | 39 | { |
| 40 | - if($code) { |
|
| 40 | + if ($code) { |
|
| 41 | 41 | return isset($this->_errors[$code]) |
| 42 | 42 | ? $this->_errors[$code] |
| 43 | 43 | : []; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $result = []; |
| 54 | 54 | foreach ($this->getErrors() as $field => $errors) { |
| 55 | - if($errors) { |
|
| 55 | + if ($errors) { |
|
| 56 | 56 | $result[$field] = reset($errors); |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function resetErrors($code = null) |
| 66 | 66 | { |
| 67 | - if($code) { |
|
| 67 | + if ($code) { |
|
| 68 | 68 | unset($this->_errors[$code]); |
| 69 | 69 | } |
| 70 | 70 | else { |
@@ -66,8 +66,7 @@ |
||
| 66 | 66 | { |
| 67 | 67 | if($code) { |
| 68 | 68 | unset($this->_errors[$code]); |
| 69 | - } |
|
| 70 | - else { |
|
| 69 | + } else { |
|
| 71 | 70 | $this->_errors = []; |
| 72 | 71 | } |
| 73 | 72 | } |