| Conditions | 4 |
| Paths | 4 |
| Total Lines | 14 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | 40 | public function build($data) |
|
| 24 | { |
||
| 25 | 40 | switch (gettype($data)) { |
|
| 26 | 40 | case 'array': |
|
| 27 | 10 | case 'object': |
|
| 28 | 33 | $this->buildFromData($data); |
|
| 29 | 33 | break; |
|
| 30 | 8 | case 'string': |
|
| 31 | 6 | $this->buildFromJson($data); |
|
| 32 | 4 | break; |
|
| 33 | default: |
||
| 34 | 2 | throw new \InvalidArgumentException('DTO can be built from array|object|json, "'.gettype($data).'" given.'); |
|
| 35 | } |
||
| 36 | 36 | } |
|
| 37 | |||
| 72 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: