| 1 | <?php declare(strict_types=1); |
||
| 13 | trait CodeTrait |
||
| 14 | { |
||
| 15 | /** @var array Collection of code lines */ |
||
| 16 | protected $code = []; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Define code condition block. |
||
| 20 | * |
||
| 21 | * @return IfGenerator Condition generator instance |
||
| 22 | */ |
||
| 23 | public function defIf(): IfGenerator |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Add function code line. |
||
| 30 | * |
||
| 31 | * @param string $code Code line |
||
| 32 | * |
||
| 33 | * @return $this |
||
| 34 | */ |
||
| 35 | 24 | public function defLine(string $code) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Build arguments list with types. |
||
| 44 | * |
||
| 45 | * @param array $arguments Arguments collection |
||
| 46 | * @param array $defaults Arguments default values collection |
||
| 47 | * |
||
| 48 | * @return string Arguments list |
||
| 49 | */ |
||
| 50 | 20 | protected function buildArguments(array $arguments, array $defaults = []) : string |
|
| 63 | } |
||
| 64 |
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: