| Conditions | 5 |
| Paths | 6 |
| Total Lines | 39 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 17 | public function parse($fields) |
||
| 18 | { |
||
| 19 | if (! $fields) { |
||
| 20 | return []; |
||
| 21 | } |
||
| 22 | |||
| 23 | // name:string, age:integer |
||
| 24 | // name:string(10,2), age:integer |
||
| 25 | $fields = preg_split('/\s?,\s/', $fields); |
||
| 26 | |||
| 27 | $parsed = []; |
||
| 28 | |||
| 29 | foreach ($fields as $index => $field) { |
||
| 30 | // Example: |
||
| 31 | // name:string:nullable => ['name', 'string', 'nullable'] |
||
| 32 | // name:string(15):nullable |
||
| 33 | $chunks = preg_split('/\s?:\s?/', $field, null); |
||
| 34 | |||
| 35 | // The first item will be our property |
||
| 36 | $property = array_shift($chunks); |
||
| 37 | |||
| 38 | $args = null; |
||
| 39 | |||
| 40 | // Finally, anything that remains will |
||
| 41 | // be our decorators |
||
| 42 | $decorators = $chunks; |
||
| 43 | |||
| 44 | $parsed[$index] = $property; |
||
| 45 | |||
| 46 | if (isset($args)) { |
||
| 47 | $parsed[$index]['args'] = $args; |
||
| 48 | } |
||
| 49 | if ($decorators) { |
||
|
|
|||
| 50 | $parsed[$index]['decorators'] = $decorators; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | return $parsed; |
||
| 55 | } |
||
| 56 | } |
||
| 57 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.