| Total Complexity | 12 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | final class ArrayOffsetHttpFields implements HttpFieldsInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | private $offset; |
||
| 22 | |||
| 23 | |||
| 24 | /** |
||
| 25 | * ArrayOffsetHttpFields constructor. |
||
| 26 | * |
||
| 27 | * @param string $offset The field name |
||
| 28 | */ |
||
| 29 | 281 | public function __construct(string $offset) |
|
| 30 | { |
||
| 31 | 281 | $this->offset = $offset; |
|
| 32 | 281 | } |
|
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritdoc} |
||
| 36 | */ |
||
| 37 | 101 | public function extract($httpFields, $defaultValue) |
|
| 38 | { |
||
| 39 | 101 | if (!is_array($httpFields) || !isset($httpFields[$this->offset])) { |
|
| 40 | 23 | return $defaultValue; |
|
| 41 | } |
||
| 42 | |||
| 43 | 82 | $value = $httpFields[$this->offset]; |
|
| 44 | |||
| 45 | // No default value : return the real submitted value |
||
| 46 | 82 | if ($defaultValue === null) { |
|
| 47 | 77 | return $value; |
|
| 48 | } |
||
| 49 | |||
| 50 | 5 | return $value !== '' && $value !== null && $value !== [] ? $value : $defaultValue; |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | 11 | public function contains($httpFields): bool |
|
| 57 | { |
||
| 58 | 11 | return isset($httpFields[$this->offset]); |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * {@inheritdoc} |
||
| 63 | */ |
||
| 64 | 6 | public function format($value) |
|
| 65 | { |
||
| 66 | 6 | return [$this->offset => $value]; |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | 14 | public function get(?HttpFieldPath $path = null): HttpFieldPath |
|
| 75 | } |
||
| 76 | } |
||
| 77 |