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