diff --git a/src/Base/Concern/OffsetGetByPhpVersion.php b/src/Base/Concern/OffsetGetByPhpVersion.php new file mode 100644 index 000000000..a0d6c6d05 --- /dev/null +++ b/src/Base/Concern/OffsetGetByPhpVersion.php @@ -0,0 +1,25 @@ += 80000) { + trait OffsetGetByPhpVersion + { + use OffsetGetPhp8; + } +} else { + trait OffsetGetByPhpVersion + { + use OffsetGetPhp7; + } +} diff --git a/src/Base/Concern/OffsetGetPhp7.php b/src/Base/Concern/OffsetGetPhp7.php new file mode 100644 index 000000000..7725f4592 --- /dev/null +++ b/src/Base/Concern/OffsetGetPhp7.php @@ -0,0 +1,20 @@ +getAttribute($offset); + } +} diff --git a/src/Base/Concern/OffsetGetPhp8.php b/src/Base/Concern/OffsetGetPhp8.php new file mode 100644 index 000000000..be62ca8c2 --- /dev/null +++ b/src/Base/Concern/OffsetGetPhp8.php @@ -0,0 +1,21 @@ +getAttribute($offset); + } +} diff --git a/src/Base/Model/Model.php b/src/Base/Model/Model.php index ef48606ae..7d2b0e4ba 100644 --- a/src/Base/Model/Model.php +++ b/src/Base/Model/Model.php @@ -6,6 +6,7 @@ use ArrayAccess; use MyParcelNL\Pdk\Base\Concern\HasAttributes; +use MyParcelNL\Pdk\Base\Concern\OffsetGetByPhpVersion; use MyParcelNL\Pdk\Base\Contract\Arrayable; use MyParcelNL\Pdk\Base\Contract\ModelInterface; use MyParcelNL\Pdk\Base\Contract\StorableArrayable; @@ -17,6 +18,7 @@ */ class Model implements StorableArrayable, ArrayAccess, ModelInterface { + use OffsetGetByPhpVersion; use HasAttributes; /** @@ -191,18 +193,6 @@ public function offsetExists($offset): bool return null !== $this->getAttribute($offset); } - /** - * Get the value for a given offset. - * - * @param mixed $offset - * - * @return mixed - */ - public function offsetGet($offset) - { - return $this->getAttribute($offset); - } - /** * Set the value for a given offset. *