| 1 | <?php |
||
| 11 | class DTOBaseBuilder |
||
| 12 | { |
||
| 13 | 40 | public function __construct(DTOBase $dtoBase) |
|
| 17 | |||
| 18 | /** |
||
| 19 | * Build DTO from given type of data |
||
| 20 | * @param $data |
||
| 21 | * @throws \InvalidArgumentException |
||
| 22 | */ |
||
| 23 | 40 | public function build($data) |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Build DTO from provided data |
||
| 40 | * @param object|array $data |
||
| 41 | */ |
||
| 42 | 36 | private function buildFromData($data) |
|
| 54 | |||
| 55 | /** |
||
| 56 | * Try to build from provided string as JSON |
||
| 57 | * @param string $data |
||
| 58 | * @throws \InvalidArgumentException |
||
| 59 | */ |
||
| 60 | 6 | private function buildFromJson($data) |
|
| 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: