| Conditions | 3 |
| Paths | 3 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | public function setAttribute($key, $enumObject) |
||
| 17 | { |
||
| 18 | if (! isset($this->enums[$key])) { |
||
|
|
|||
| 19 | return parent::setAttribute($key, $enumObject); |
||
| 20 | } |
||
| 21 | |||
| 22 | $enumClass = $this->enums[$key]; |
||
| 23 | |||
| 24 | if (! is_a($enumObject, $enumClass)) { |
||
| 25 | throw InvalidEnumError::make( |
||
| 26 | static::class, |
||
| 27 | $key, |
||
| 28 | $enumClass, |
||
| 29 | get_class($enumObject) |
||
| 30 | ); |
||
| 31 | } |
||
| 32 | |||
| 33 | $enumValue = $enumObject->getValue(); |
||
| 34 | |||
| 35 | $mappedValue = $enumClass::$map[$enumValue] ?? null; |
||
| 36 | |||
| 37 | $this->attributes[$key] = $mappedValue ?? $enumValue; |
||
| 38 | |||
| 39 | return $this; |
||
| 40 | } |
||
| 41 | |||
| 73 |
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: