Conditions | 2 |
Paths | 2 |
Total Lines | 12 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
60 | 6 | private function buildFromJson($data) |
|
61 | { |
||
62 | 6 | $triedToDecodeData = json_decode($data); |
|
63 | |||
64 | 6 | if ($triedToDecodeData !== null) { |
|
65 | 4 | $this->buildFromData($triedToDecodeData); |
|
66 | } else { |
||
67 | 2 | throw new \InvalidArgumentException( |
|
68 | 2 | 'DTO can be built from array|object|json, "'.gettype($data).'" given. Probably tried to pass invalid JSON.' |
|
69 | ); |
||
70 | } |
||
71 | } |
||
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: