Commit 9dcd1254 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

REFACTOR: move polyfills (array_key_last and array_key_first)

parent 630cfff5
<?php
// Here you can initialize variables that will be available to your tests, e.g. the app's bootstrap.php
// Polyfill for array_key_first() function added in PHP 7.3.
if (!function_exists('array_key_first')) {
function array_key_first(array $array)
{
if ($array === []) {
return null;
}
foreach ($array as $key => $_) {
return $key;
}
}
}
// Polyfill for array_key_last() function added in PHP 7.3.
if (!function_exists('array_key_last')) {
function array_key_last(array $array)
{
if ($array === []) {
return null;
}
return array_key_first(array_slice($array, -1));
}
}
......@@ -6,3 +6,27 @@
* unit tests in this file.
*/
require dirname(__DIR__) . '/config/bootstrap.php';
// Polyfill for array_key_first() function added in PHP 7.3.
if (!function_exists('array_key_first')) {
function array_key_first(array $array)
{
if ($array === []) {
return null;
}
foreach ($array as $key => $_) {
return $key;
}
}
}
// Polyfill for array_key_last() function added in PHP 7.3.
if (!function_exists('array_key_last')) {
function array_key_last(array $array)
{
if ($array === []) {
return null;
}
return array_key_first(array_slice($array, -1));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment