@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | $filtered = []; |
75 | 75 | $rules = collect($this->buildRules()); |
76 | 76 | $keys = $rules->keys(); |
77 | - $rules->each(function ($rules, $key) use ($original, $keys, &$filtered) { |
|
77 | + $rules->each(function($rules, $key) use ($original, $keys, &$filtered) { |
|
78 | 78 | //Allow for array or pipe-delimited rule-sets |
79 | 79 | if (is_string($rules)) { |
80 | 80 | $rules = explode('|', $rules); |
81 | 81 | } |
82 | 82 | //In case a rule requires an element to be an array, look for nested rules |
83 | - $nestedRules = $keys->filter(function ($otherKey) use ($key) { |
|
83 | + $nestedRules = $keys->filter(function($otherKey) use ($key) { |
|
84 | 84 | return strpos($otherKey, "$key.") === 0; |
85 | 85 | }); |
86 | 86 | //If the input must be an array, default missing nested rules to a wildcard |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | } |
142 | 142 | |
143 | 143 | if (method_exists($this, 'afterValidator')) { |
144 | - $validator->after(function ($validator) { |
|
144 | + $validator->after(function($validator) { |
|
145 | 145 | $this->resolveAndCall($this, 'afterValidator', compact('validator')); |
146 | 146 | }); |
147 | 147 | } |
@@ -10,11 +10,11 @@ discard block |
||
10 | 10 | protected function resolveAttributeCasting(array $data) |
11 | 11 | { |
12 | 12 | $attributes = (new Collection($this->rules())) |
13 | - ->filter(function ($rule) { |
|
13 | + ->filter(function($rule) { |
|
14 | 14 | return $rule instanceof Attribute; |
15 | 15 | }); |
16 | 16 | |
17 | - return $attributes->intersectByKeys($data)->map(function (Attribute $attribute, $key) use ($data) { |
|
17 | + return $attributes->intersectByKeys($data)->map(function(Attribute $attribute, $key) use ($data) { |
|
18 | 18 | return $this->processCasting($attribute, $data[$key]); |
19 | 19 | })->toArray(); |
20 | 20 | } |
@@ -40,20 +40,20 @@ discard block |
||
40 | 40 | switch (strtolower($type)) { |
41 | 41 | case "boolean": |
42 | 42 | case "bool" : |
43 | - return (bool)$value; |
|
43 | + return (bool) $value; |
|
44 | 44 | case "string": |
45 | - return (string)$value; |
|
45 | + return (string) $value; |
|
46 | 46 | case "double": |
47 | - return (double)$value; |
|
47 | + return (double) $value; |
|
48 | 48 | case "integer": |
49 | 49 | case "int": |
50 | - return (int)$value; |
|
50 | + return (int) $value; |
|
51 | 51 | case "float": |
52 | - return (float)$value; |
|
52 | + return (float) $value; |
|
53 | 53 | case "array": |
54 | - return (array)$value; |
|
54 | + return (array) $value; |
|
55 | 55 | case "object": |
56 | - return (object)$value; |
|
56 | + return (object) $value; |
|
57 | 57 | default: |
58 | 58 | throw new \RuntimeException("cast type not supported"); |
59 | 59 | } |
@@ -21,16 +21,18 @@ |
||
21 | 21 | |
22 | 22 | private function processCasting(Attribute $attribute, $value) |
23 | 23 | { |
24 | - if (($castFunction = $attribute->getCast()) !== null && is_callable($castFunction)) |
|
25 | - return $castFunction($value); |
|
24 | + if (($castFunction = $attribute->getCast()) !== null && is_callable($castFunction)) { |
|
25 | + return $castFunction($value); |
|
26 | + } |
|
26 | 27 | |
27 | 28 | if ((($type = $attribute->getCast()) !== null && is_string($type)) || |
28 | 29 | (is_string($type = $attribute->cast(null)) && in_array(strtolower($type), ["bool", "boolean", "string", "double", "float", "int", "integer", "array", "object"]))) { |
29 | 30 | return $this->castFromString($type, $value); |
30 | 31 | } |
31 | 32 | |
32 | - if (!($attribute->cast(null) instanceof Attribute)) |
|
33 | - return $attribute->cast($value); |
|
33 | + if (!($attribute->cast(null) instanceof Attribute)) { |
|
34 | + return $attribute->cast($value); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | return $value; |
36 | 38 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $attribute = static::make(); |
66 | 66 | $attribute->setRules( |
67 | 67 | collect($attribute->getRules()) |
68 | - ->reject(function ($value) { |
|
68 | + ->reject(function($value) { |
|
69 | 69 | return $value === 'required'; |
70 | 70 | }) |
71 | 71 | ->toArray() |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | return $this->data['rules']; |
125 | 125 | } |
126 | 126 | |
127 | - public function getPreProcessing(){ |
|
127 | + public function getPreProcessing() { |
|
128 | 128 | return $this->preProcess; |
129 | 129 | } |
130 | 130 | |
131 | - public function getCast(){ |
|
131 | + public function getCast() { |
|
132 | 132 | return $this->cast; |
133 | 133 | } |
134 | 134 |
@@ -54,8 +54,9 @@ |
||
54 | 54 | |
55 | 55 | public function cast($cast) |
56 | 56 | { |
57 | - if (is_callable($cast) || is_string($cast)) |
|
58 | - $this->cast = $cast; |
|
57 | + if (is_callable($cast) || is_string($cast)) { |
|
58 | + $this->cast = $cast; |
|
59 | + } |
|
59 | 60 | |
60 | 61 | return $this; |
61 | 62 | } |