protected function insertInArray($array, $key, $value, $beforeKey)
    {
        // Find the position of the array
        $position = array_search($beforeKey, array_keys($array));

        // Safeguard: silently append if injected position could not be found
        if (false === $position) {
            // @codeCoverageIgnoreStart
            $array[ $key ] = $value;
            return $array;
            // @codeCoverageIgnoreEnd
        }

        if (0 === $position) {
            return [ $key => $value ] + $array;
        }

        // Slice the array up with the new entry in between
        return array_slice($array, 0, $position, true)
             + [ $key => $value ]
             + array_slice($array, $position, count($array) - $position, true);
    }