| Conditions | 9 |
| Paths | 9 |
| Total Lines | 37 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 9 |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | 2 | public function toArray() |
|
| 12 | { |
||
| 13 | 2 | $this->setExportedVariables(); |
|
|
|
|||
| 14 | 2 | $result = []; |
|
| 15 | 2 | foreach ($this->exportedVariables as $sourceName => $destinationName) { |
|
| 16 | 2 | $omitEmpty = false; |
|
| 17 | 2 | $castType = null; |
|
| 18 | 2 | if (strpos($destinationName, ',') !== false) { |
|
| 19 | 1 | $splitted = explode(',', $destinationName); |
|
| 20 | array_map(function ($item) use (&$castType, &$omitEmpty) { |
||
| 21 | 1 | if ($item === 'omitempty') { |
|
| 22 | 1 | $omitEmpty = true; |
|
| 23 | 1 | return; |
|
| 24 | } |
||
| 25 | 1 | if (substr($item, 0, 5) === 'type:') { |
|
| 26 | 1 | $castType = substr($item, 5); |
|
| 27 | } |
||
| 28 | 1 | }, $splitted); |
|
| 29 | |||
| 30 | 1 | $destinationName = $splitted[0]; |
|
| 31 | } |
||
| 32 | |||
| 33 | 2 | if ($destinationName === '-') { |
|
| 34 | 1 | continue; |
|
| 35 | } |
||
| 36 | |||
| 37 | 2 | if ($omitEmpty && empty($this->$sourceName)) { |
|
| 38 | 1 | continue; |
|
| 39 | } |
||
| 40 | 2 | $value = $this->$sourceName; |
|
| 41 | 2 | if ($castType !== null) { |
|
| 42 | 1 | settype($value, $castType); |
|
| 43 | } |
||
| 44 | 2 | $result[$destinationName] = $value; |
|
| 45 | } |
||
| 46 | |||
| 47 | 2 | return $result; |
|
| 48 | } |
||
| 59 | } |