Completed
Push — master ( d669e8...355804 )
by James Ekow Abaka
02:29
created
src/RecordWrapper.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,6 @@
 block discarded – undo
25 25
 
26 26
 namespace ntentan\nibii;
27 27
 
28
-use ntentan\utils\Utils;
29 28
 use ntentan\kaikai\Cache;
30 29
 
31 30
 class RecordWrapper implements \ArrayAccess, \Countable, \Iterator
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     public function __construct()
48 48
     {
49 49
         $this->table = Nibii::getModelTable($this);
50
-        foreach($this->behaviours as $behaviour) {
50
+        foreach ($this->behaviours as $behaviour) {
51 51
             $behaviourInstance = $this->getComponentInstance($behaviour);
52 52
             $behaviourInstance->setModel($this);
53 53
         }
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      */
60 60
     protected function getDataAdapter()
61 61
     {
62
-        if(!$this->adapter)
62
+        if (!$this->adapter)
63 63
         {
64 64
             $this->adapter = DriverAdapter::getDefaultInstance();
65 65
         }
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     public function getDescription()
74 74
     {
75 75
         return Cache::read(
76
-            (new \ReflectionClass($this))->getName() . '::desc',
76
+            (new \ReflectionClass($this))->getName().'::desc',
77 77
             function() 
78 78
             {
79 79
                 return new ModelDescription($this);
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     private function retrieveItem($key)
94 94
     {
95 95
         $relationships = $this->getDescription()->getRelationships();
96
-        if(isset($relationships[$key])) {
96
+        if (isset($relationships[$key])) {
97 97
             return $this->fetchRelatedFields($relationships[$key]);
98 98
         } else {
99 99
             return isset($this->modelData[$key]) ? $this->modelData[$key] : null;
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      */
119 119
     public function __call($name, $arguments)
120 120
     {
121
-        if($this->dynamicOperations === null) {
121
+        if ($this->dynamicOperations === null) {
122 122
             $this->dynamicOperations = new Operations($this, $this->getDataAdapter());
123 123
         }
124 124
         return $this->dynamicOperations->perform($name, $arguments);
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     
148 148
     private function expandArrayValue($array, $relationships, $depth, $index = null)
149 149
     {
150
-        foreach($relationships as $name => $relationship) {
150
+        foreach ($relationships as $name => $relationship) {
151 151
             $array[$name] = $this->fetchRelatedFields($relationship, $index)->toArray($depth);
152 152
         }
153 153
         return $array;
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
     {
158 158
         $relationships = $this->getDescription()->getRelationships();
159 159
         $array = $this->modelData;
160
-        if($depth > 0) {
161
-            if($this->hasMultipleData()) {
162
-                foreach($array as $i => $value) {
160
+        if ($depth > 0) {
161
+            if ($this->hasMultipleData()) {
162
+                foreach ($array as $i => $value) {
163 163
                     $array[$i] = $this->expandArrayValue($value, $relationships, $depth - 1, $i);
164 164
                 }
165 165
             } else {
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 
184 184
     private function hasMultipleData()
185 185
     {
186
-        if(count($this->modelData) > 0) {
186
+        if (count($this->modelData) > 0) {
187 187
             return is_numeric(array_keys($this->modelData)[0]);
188 188
         } else {
189 189
             return false;
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
     {
195 195
         $data = [];
196 196
                 
197
-        if(count($this->modelData) == 0) {
197
+        if (count($this->modelData) == 0) {
198 198
             $data = $this->modelData;
199
-        } else if($this->hasMultipleData()) {
199
+        } else if ($this->hasMultipleData()) {
200 200
             $data = $this->modelData;
201
-        } else if(count($this->modelData) > 0) {
201
+        } else if (count($this->modelData) > 0) {
202 202
             $data[] = $this->modelData;
203 203
         }
204 204
         
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     
214 214
     public function mergeData($data)
215 215
     {
216
-        foreach($data as $key => $value) {
216
+        foreach ($data as $key => $value) {
217 217
             $this->modelData[$key] = $value;
218 218
         }
219 219
         $this->dataSet = true;
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 
247 247
     private function wrap($offset)
248 248
     {
249
-        if(isset($this->modelData[$offset])) {
249
+        if (isset($this->modelData[$offset])) {
250 250
             $newInstance = $this->createNew();
251 251
             $newInstance->setData($this->modelData[$offset]);
252 252
             return $newInstance;
@@ -297,13 +297,13 @@  discard block
 block discarded – undo
297 297
 
298 298
     private function fetchRelatedFields($relationship, $index = null)
299 299
     {
300
-        if($index === null) {
300
+        if ($index === null) {
301 301
             $data = $this->modelData;
302 302
         } else {
303 303
             $data = $this->modelData[$index];
304 304
         }
305 305
         $model = $relationship->getModelInstance();
306
-        if(empty($data)) {
306
+        if (empty($data)) {
307 307
             return $model;
308 308
         } else {
309 309
             return $model->fetch($relationship->getQuery($data));
Please login to merge, or discard this patch.