Conditions | 3 |
Paths | 3 |
Total Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
34 | public function setAttributeEnum(string $key, $value, string $class) |
||
35 | { |
||
36 | if (! class_exists($class)) { |
||
37 | throw new EnumException(sprintf('Enumerable class "%s" doesn\'t exist', $class)); |
||
38 | } |
||
39 | |||
40 | if (! $class::hasValue($value)) { |
||
41 | throw new InvalidEnumValueException(sprintf( |
||
42 | 'Value "%s" is not allowed for attribute "%s"', |
||
43 | $value, $key |
||
44 | )); |
||
45 | } |
||
46 | |||
47 | $this->attributes[$key] = $value; |
||
|
|||
48 | |||
49 | return $this; |
||
50 | } |
||
51 | } |
||
52 |
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: