Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ArrayAccessConfigTrait
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 offsetExists
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetGet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetUnset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * This file is part of php-fast-forward/config.
7 *
8 * This source file is subject to the license bundled
9 * with this source code in the file LICENSE.
10 *
11 * @copyright Copyright (c) 2025-2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/config
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Config;
20
21/**
22 * Trait ArrayAccessConfigTrait.
23 *
24 * This trait provides array-like access to configuration data.
25 * It MUST be used in classes that implement \ArrayAccess and provide
26 * the corresponding methods: `get`, `set`, `has`, and `remove`.
27 *
28 * @internal
29 *
30 * @see \ArrayAccess
31 */
32trait ArrayAccessConfigTrait
33{
34    /**
35     * Determines whether the given offset exists in the configuration data.
36     *
37     * This method SHALL return true if the offset is present, false otherwise.
38     *
39     * @param mixed $offset the offset to check for existence
40     *
41     * @return bool true if the offset exists, false otherwise
42     */
43    public function offsetExists(mixed $offset): bool
44    {
45        return $this->has($offset);
46    }
47
48    /**
49     * Retrieves the value associated with the given offset.
50     *
51     * This method MUST return the value mapped to the specified offset.
52     * If the offset does not exist, behavior SHALL depend on the implementation
53     * of the `get` method.
54     *
55     * @param mixed $offset the offset to retrieve
56     *
57     * @return mixed the value at the given offset
58     */
59    public function offsetGet(mixed $offset): mixed
60    {
61        return $this->get($offset);
62    }
63
64    /**
65     * Sets the value for the specified offset.
66     *
67     * This method SHALL assign the given value to the specified offset.
68     *
69     * @param mixed $offset the offset at which to set the value
70     * @param mixed $value the value to set
71     *
72     * @return void
73     */
74    public function offsetSet(mixed $offset, mixed $value): void
75    {
76        $this->set($offset, $value);
77    }
78
79    /**
80     * Unsets the specified offset.
81     *
82     * This method SHALL remove the specified offset and its associated value.
83     *
84     * @param mixed $offset the offset to remove
85     *
86     * @return void
87     */
88    public function offsetUnset(mixed $offset): void
89    {
90        $this->remove($offset);
91    }
92}