BuildsCastQueries::type()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 4
1
<?php
2
3
namespace Koch\Casters\Behavior;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
trait BuildsCastQueries
8
{
9
    /**
10
     * Builds up the cast query.
11
     *
12
     * @param  string  $old
13
     * @param  string  $query
14
     * @param  \Illuminate\Database\Eloquent\Model  $model
15
     * @param  array  &$transformed
16
     * @return array
17
     */
18
    protected function parse($old, $query, Model $model, &$transformed)
19
    {
20
        $key = $old;
21
        $value = $model->$old;
22
23
        foreach (explode('|', $query) as $command) {
24
            list($function, $args) = explode(':', $command);
25
26
            $args = array_merge([&$key, &$value, $model], explode(',', $args));
27
28
            call_user_func_array([$this, $function], $args);
29
        }
30
31
        return $transformed[$key] = $value;
32
    }
33
34
    /**
35
     * Adjusts the name of given field.
36
     *
37
     * @param  string  &$key
38
     * @param  string  &$value
39
     * @param  \Illuminate\Database\Eloquent\Model  $model
40
     * @param  string  $newName
41
     * @return void
42
     */
43
    protected function name(&$key, &$value, Model $model, $newName)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45
        $key = $newName;
46
    }
47
48
    /**
49
     * Adjusts the data type of given field.
50
     *
51
     * @param  string  &$key
52
     * @param  string  &$value
53
     * @param  \Illuminate\Database\Eloquent\Model  $model
54
     * @param  string  $type
55
     * @return void
56
     */
57
    protected function type(&$key, &$value, Model $model, $type)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        settype($value, $type);
60
    }
61
}
62