| Conditions | 11 |
| Paths | 48 |
| Total Lines | 39 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 28 | public function bulkSerialise($model) |
||
| 29 | { |
||
| 30 | $class = get_class($model); |
||
| 31 | assert($model instanceof Model, $class); |
||
| 32 | // dig up metadata |
||
| 33 | if (!isset(self::$metadataCache[$class])) { |
||
| 34 | self::$metadataCache[$class] = $model->metadata(); |
||
| 35 | } |
||
| 36 | $model->synthLiteralPK(); |
||
| 37 | $meta = self::$metadataCache[$class]; |
||
| 38 | $keys = array_keys($meta); |
||
| 39 | // dig up getter list - we only care about the mutators that end up in metadata |
||
| 40 | if (!isset(self::$mutatorCache[$class])) { |
||
| 41 | $getterz = []; |
||
| 42 | $datez = $model->getDates(); |
||
| 43 | $castz = $model->retrieveCasts(); |
||
| 44 | foreach ($keys as $key) { |
||
| 45 | if ($model->hasGetMutator($key) || in_array($key, $datez) || array_key_exists($key, $castz)) { |
||
| 46 | $getterz[] = $key; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | self::$mutatorCache[$class] = $getterz; |
||
| 50 | } |
||
| 51 | $getterz = self::$mutatorCache[$class]; |
||
| 52 | $modelAttrib = $model->getAttributes(); |
||
| 53 | $result = array_intersect_key($modelAttrib, $meta); |
||
| 54 | foreach ($keys as $key) { |
||
| 55 | if (!isset($result[$key])) { |
||
| 56 | $result[$key] = null; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | foreach ($getterz as $getter) { |
||
| 60 | $result[$getter] = $model->$getter; |
||
| 61 | } |
||
| 62 | if (isset($modelAttrib[LaravelReadQuery::PK])) { |
||
| 63 | $result[LaravelReadQuery::PK] = $modelAttrib[LaravelReadQuery::PK]; |
||
| 64 | } |
||
| 65 | |||
| 66 | return $result; |
||
| 67 | } |
||
| 75 |