@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | public function insert($record) |
80 | 80 | { |
81 | - if($this->insertQuery === null) { |
|
81 | + if ($this->insertQuery === null) { |
|
82 | 82 | $this->initInsert(); |
83 | 83 | } |
84 | 84 | return Db::getDriver()->query($this->insertQuery, $record); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | public function update($record) |
88 | 88 | { |
89 | - if($this->updateQuery === null) { |
|
89 | + if ($this->updateQuery === null) { |
|
90 | 90 | $this->initUpdate(); |
91 | 91 | } |
92 | 92 | return Db::getDriver()->query($this->updateQuery, $record); |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace ntentan\nibii; |
4 | 4 | |
5 | -use ntentan\utils\Text; |
|
6 | 5 | use ntentan\atiaa\Db; |
7 | 6 | |
8 | 7 | /** |
@@ -8,10 +8,10 @@ |
||
8 | 8 | |
9 | 9 | namespace ntentan\nibii; |
10 | 10 | |
11 | +use ntentan\config\Config; |
|
11 | 12 | use ntentan\nibii\interfaces\ClassResolverInterface; |
12 | 13 | use ntentan\nibii\interfaces\ModelJoinerInterface; |
13 | 14 | use ntentan\nibii\interfaces\TableNameResolverInterface; |
14 | -use ntentan\config\Config; |
|
15 | 15 | use ntentan\utils\Text; |
16 | 16 | |
17 | 17 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | { |
25 | 25 | public function getModelClassName($default, $context) |
26 | 26 | { |
27 | - if(self::$classResolver !== null && $model[0] !== "\\") { |
|
27 | + if (self::$classResolver !== null && $model[0] !== "\\") { |
|
28 | 28 | $resolver = self::$classResolver; |
29 | 29 | $className = $resolver($model, $context); |
30 | 30 | } else { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | { |
38 | 38 | $arrayed = explode('\\', $className); |
39 | 39 | $class = array_pop($arrayed); |
40 | - if($arrayed[0] == '') { |
|
40 | + if ($arrayed[0] == '') { |
|
41 | 41 | array_shift($arrayed); |
42 | 42 | } |
43 | 43 | return ['class' => $class, 'namespace' => implode('\\', $arrayed)]; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | { |
48 | 48 | $classA = $this->getClassFileDetails($classA); |
49 | 49 | $classB = $this->getClassFileDetails($classB); |
50 | - if($classA['namespace'] != $classB['namespace']) { |
|
50 | + if ($classA['namespace'] != $classB['namespace']) { |
|
51 | 51 | throw new NibiiException( |
52 | 52 | "Cannot automatically join two classes of different " |
53 | 53 | . "namespaces. Please provide a model joiner or " |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | $classes = [$classA['class'], $classB['class']]; |
58 | 58 | sort($classes); |
59 | - return "{$classA['namespace']}\\" . implode('', $classes); |
|
59 | + return "{$classA['namespace']}\\".implode('', $classes); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | public function getTableName($instance) |
@@ -68,6 +68,6 @@ discard block |
||
68 | 68 | |
69 | 69 | public static function getDriverAdapterClassName() |
70 | 70 | { |
71 | - return __NAMESPACE__ . '\adapters\\' . Text::ucamelize(Config::get('ntentan:db.driver')) . 'Adapter'; |
|
71 | + return __NAMESPACE__.'\adapters\\'.Text::ucamelize(Config::get('ntentan:db.driver')).'Adapter'; |
|
72 | 72 | } |
73 | 73 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | { |
50 | 50 | $this->table = Nibii::getModelTable($this); |
51 | 51 | $this->adapter = $adapter; |
52 | - foreach($this->behaviours as $behaviour) { |
|
52 | + foreach ($this->behaviours as $behaviour) { |
|
53 | 53 | $behaviourInstance = $this->getComponentInstance($behaviour); |
54 | 54 | $behaviourInstance->setModel($this); |
55 | 55 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | public function getDescription() |
77 | 77 | { |
78 | 78 | return Cache::read( |
79 | - (new \ReflectionClass($this))->getName() . '::desc', |
|
79 | + (new \ReflectionClass($this))->getName().'::desc', |
|
80 | 80 | function() |
81 | 81 | { |
82 | 82 | return new ModelDescription($this); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | private function retrieveItem($key) |
97 | 97 | { |
98 | 98 | $relationships = $this->getDescription()->getRelationships(); |
99 | - if(isset($relationships[$key])) { |
|
99 | + if (isset($relationships[$key])) { |
|
100 | 100 | return $this->fetchRelatedFields($relationships[$key]); |
101 | 101 | } else { |
102 | 102 | return isset($this->modelData[$key]) ? $this->modelData[$key] : null; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function __call($name, $arguments) |
123 | 123 | { |
124 | - if($this->dynamicOperations === null) { |
|
124 | + if ($this->dynamicOperations === null) { |
|
125 | 125 | $this->dynamicOperations = new Operations($this, InjectionContainer::singleton(DriverAdapter::class)); |
126 | 126 | } |
127 | 127 | return $this->dynamicOperations->perform($name, $arguments); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | |
151 | 151 | private function expandArrayValue($array, $relationships, $depth, $index = null) |
152 | 152 | { |
153 | - foreach($relationships as $name => $relationship) { |
|
153 | + foreach ($relationships as $name => $relationship) { |
|
154 | 154 | $array[$name] = $this->fetchRelatedFields($relationship, $index)->toArray($depth); |
155 | 155 | } |
156 | 156 | return $array; |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | { |
161 | 161 | $relationships = $this->getDescription()->getRelationships(); |
162 | 162 | $array = $this->modelData; |
163 | - if($depth > 0) { |
|
164 | - if($this->hasMultipleData()) { |
|
165 | - foreach($array as $i => $value) { |
|
163 | + if ($depth > 0) { |
|
164 | + if ($this->hasMultipleData()) { |
|
165 | + foreach ($array as $i => $value) { |
|
166 | 166 | $array[$i] = $this->expandArrayValue($value, $relationships, $depth - 1, $i); |
167 | 167 | } |
168 | 168 | } else { |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | private function hasMultipleData() |
188 | 188 | { |
189 | - if(count($this->modelData) > 0) { |
|
189 | + if (count($this->modelData) > 0) { |
|
190 | 190 | return is_numeric(array_keys($this->modelData)[0]); |
191 | 191 | } else { |
192 | 192 | return false; |
@@ -197,11 +197,11 @@ discard block |
||
197 | 197 | { |
198 | 198 | $data = []; |
199 | 199 | |
200 | - if(count($this->modelData) == 0) { |
|
200 | + if (count($this->modelData) == 0) { |
|
201 | 201 | $data = $this->modelData; |
202 | - } else if($this->hasMultipleData()) { |
|
202 | + } else if ($this->hasMultipleData()) { |
|
203 | 203 | $data = $this->modelData; |
204 | - } else if(count($this->modelData) > 0) { |
|
204 | + } else if (count($this->modelData) > 0) { |
|
205 | 205 | $data[] = $this->modelData; |
206 | 206 | } |
207 | 207 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | |
217 | 217 | public function mergeData($data) |
218 | 218 | { |
219 | - foreach($data as $key => $value) { |
|
219 | + foreach ($data as $key => $value) { |
|
220 | 220 | $this->modelData[$key] = $value; |
221 | 221 | } |
222 | 222 | $this->dataSet = true; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | private function wrap($offset) |
251 | 251 | { |
252 | - if(isset($this->modelData[$offset])) { |
|
252 | + if (isset($this->modelData[$offset])) { |
|
253 | 253 | $newInstance = $this->createNew(); |
254 | 254 | $newInstance->setData($this->modelData[$offset]); |
255 | 255 | return $newInstance; |
@@ -300,13 +300,13 @@ discard block |
||
300 | 300 | |
301 | 301 | private function fetchRelatedFields($relationship, $index = null) |
302 | 302 | { |
303 | - if($index === null) { |
|
303 | + if ($index === null) { |
|
304 | 304 | $data = $this->modelData; |
305 | 305 | } else { |
306 | 306 | $data = $this->modelData[$index]; |
307 | 307 | } |
308 | 308 | $model = $relationship->getModelInstance(); |
309 | - if(empty($data)) { |
|
309 | + if (empty($data)) { |
|
310 | 310 | return $model; |
311 | 311 | } else { |
312 | 312 | return $model->fetch($relationship->getQuery($data)); |