| Total Complexity | 5 |
| Total Lines | 75 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | abstract class Context |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * User defined attributes |
||
| 14 | * |
||
| 15 | * @var mixed[] |
||
| 16 | */ |
||
| 17 | protected $attributes = []; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * If the default scalar type adapters should be enabled |
||
| 21 | * |
||
| 22 | * @var bool |
||
| 23 | */ |
||
| 24 | protected $enableScalarAdapters = false; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Get an array of user defined attributes |
||
| 28 | * |
||
| 29 | * @return array |
||
| 30 | */ |
||
| 31 | 2 | public function getAttributes(): array |
|
| 32 | { |
||
| 33 | 2 | return $this->attributes; |
|
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Returns the attribute value for a given key or null if it's missing |
||
| 38 | * |
||
| 39 | * @param string $key |
||
| 40 | * @return mixed |
||
| 41 | */ |
||
| 42 | 2 | public function getAttribute(string $key) |
|
| 43 | { |
||
| 44 | 2 | return $this->attributes[$key] ?? null; |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Add a custom attribute |
||
| 49 | * |
||
| 50 | * @param string $key |
||
| 51 | * @param $value |
||
| 52 | * @return Context |
||
| 53 | */ |
||
| 54 | 2 | public function setAttribute(string $key, $value): Context |
|
| 55 | { |
||
| 56 | 2 | $this->attributes[$key] = $value; |
|
| 57 | |||
| 58 | 2 | return $this; |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * If scalar values should get sent through the type adapter |
||
| 63 | * system or if they should just be read/written in place. |
||
| 64 | * |
||
| 65 | * @return bool |
||
| 66 | */ |
||
| 67 | 5 | public function enableScalarAdapters(): bool |
|
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Defaults to true. Set to false if scalar values should be read/written |
||
| 74 | * through a type adapter. |
||
| 75 | * |
||
| 76 | * @param bool $enable |
||
| 77 | * @return Context |
||
| 78 | */ |
||
| 79 | 2 | public function setEnableScalarAdapters(bool $enable): Context |
|
| 87 |