for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace FigTree\Config\Concerns;
use ArrayIterator;
use Traversable;
use FigTree\Config\Exceptions\{
ReadOnlyException,
};
trait ArrayAccessData
{
protected array $data = [];
/**
* Magic method to handle key_exists/isset checks of an array value on the object.
*
* @param string|int $offset
* @return boolean
*/
public function offsetExists($offset): bool
return key_exists($offset, $this->data);
}
* Magic method to handle retrieval of an array value on the object.
* @return mixed
public function offsetGet($offset)
return $this->data[$offset] ?? null;
* Magic method to handle modification of an array value on the object.
* @param mixed $value
* @return void
* @throws \FigTree\Config\Exceptions\ReadOnlyException
public function offsetSet($offset, $value): void
$value
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function offsetSet($offset, /** @scrutinizer ignore-unused */ $value): void
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
throw new ReadOnlyException($offset);
* Magic method to handle removal of an array value on the object.
public function offsetUnset($offset): void
* Convert the object into an array.
* @return array
public function toArray(): array
return $this->data;
* Retrieve an external iterator.
* @return \Traversable
public function getIterator(): Traversable
return new ArrayIterator($this->data);
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.