<commit_before><?php
/**
 *
 */

namespace Mvc5\Cookie\Config;

use Mvc5\Arg;
use Mvc5\Cookie\Cookies;

use function is_array;
use function is_string;
use function key;

trait HttpCookies
{
    /**
     * @var array
     */
    protected $config = [];

    /**
     * @param array $cookies
     */
    function __construct(array $cookies = [])
    {
        $this->config = $cookies;
    }

    /**
     * @return array
     */
    function all() : array
    {
        return $this->config;
    }

    /**
     * @param array|string $name
     * @param array $options
     */
    function remove($name, array $options = []) : void
    {
        !is_array($name) ? $this->set($name, '', [Arg::EXPIRES => 946706400] + $options) : $this->set(
            [Arg::VALUE => '', Arg::EXPIRES => 946706400] + (is_string(key($name)) ? $name : cookie(...$name))
        );
    }

    /**
     * @param array|string $name
     * @param string|null $value
     * @param array $options
     * @return mixed
     */
    function set($name, $value = null, array $options = [])
    {
        if (is_array($name)) {
            $this->config[name($name)] = is_string(key($name)) ? $name : cookie(...$name);
            return $name;
        }

        $this->config[$name] = [Arg::NAME => (string) $name, Arg::VALUE => (string) $value] + $options;

        return $value;
    }

    /**
     * @param array|string $name
     * @param string|null $value
     * @param array $options
     * @return self|mixed
     */
    function with($name, $value = null, array $options = []) : Cookies
    {
        $new = clone $this;
        $new->set($name, $value, $options);
        return $new;
    }

    /**
     * @param array|string $name
     * @param array $options
     * @return self|mixed
     */
    function without($name, array $options = []) : Cookies
    {
        $new = clone $this;
        $new->remove($name, $options);
        return $new;
    }
}

/**
 * @param string $name
 * @param string $value
 * @param int|string|null $expires
 * @param string|null $path
 * @param string|null $domain
 * @param bool|null $secure
 * @param bool|null $httponly
 * @param string|null $samesite
 * @return array
 */
function cookie(string $name, string $value = null, $expires = null, string $path = null, string $domain = null,
                bool $secure = null, bool $httponly = null, string $samesite = null) : array
{
    return [
        Arg::NAME => $name,
        Arg::VALUE => $value,
        Arg::EXPIRES => $expires,
        Arg::PATH => $path,
        Arg::DOMAIN => $domain,
        Arg::SECURE => $secure,
        Arg::HTTP_ONLY => $httponly,
        Arg::SAMESITE => $samesite
    ];
}

/**
 * @param array $cookie
 * @return string
 */
function name(array $cookie) : string
{
    return (string) (is_string(key($cookie)) ? $cookie[Arg::NAME] : $cookie[0]);
}<commit_msg>remove cookie array name function<commit_after><?php
/**
 *
 */

namespace Mvc5\Cookie\Config;

use Mvc5\Arg;
use Mvc5\Cookie\Cookies;

use function is_array;
use function is_string;
use function key;

trait HttpCookies
{
    /**
     * @var array
     */
    protected $config = [];

    /**
     * @param array $cookies
     */
    function __construct(array $cookies = [])
    {
        $this->config = $cookies;
    }

    /**
     * @return array
     */
    function all() : array
    {
        return $this->config;
    }

    /**
     * @param array|string $name
     * @param array $options
     */
    function remove($name, array $options = []) : void
    {
        !is_array($name) ? $this->set($name, '', [Arg::EXPIRES => 946706400] + $options) : $this->set(
            [Arg::VALUE => '', Arg::EXPIRES => 946706400] + (is_string(key($name)) ? $name : cookie(...$name))
        );
    }

    /**
     * @param array|string $name
     * @param string|null $value
     * @param array $options
     * @return mixed
     */
    function set($name, $value = null, array $options = [])
    {
        if (is_array($name)) {
            $cookie = is_string(key($name)) ? $name : cookie(...$name);

            $this->config[$cookie[Arg::NAME]] = $cookie;

            return $name;
        }

        $this->config[$name] = [Arg::NAME => (string) $name, Arg::VALUE => (string) $value] + $options;

        return $value;
    }

    /**
     * @param array|string $name
     * @param string|null $value
     * @param array $options
     * @return self|mixed
     */
    function with($name, $value = null, array $options = []) : Cookies
    {
        $new = clone $this;
        $new->set($name, $value, $options);
        return $new;
    }

    /**
     * @param array|string $name
     * @param array $options
     * @return self|mixed
     */
    function without($name, array $options = []) : Cookies
    {
        $new = clone $this;
        $new->remove($name, $options);
        return $new;
    }
}

/**
 * @param string $name
 * @param string $value
 * @param int|string|null $expires
 * @param string|null $path
 * @param string|null $domain
 * @param bool|null $secure
 * @param bool|null $httponly
 * @param string|null $samesite
 * @return array
 */
function cookie(string $name, string $value = null, $expires = null, string $path = null, string $domain = null,
                bool $secure = null, bool $httponly = null, string $samesite = null) : array
{
    return [
        Arg::NAME => $name,
        Arg::VALUE => $value,
        Arg::EXPIRES => $expires,
        Arg::PATH => $path,
        Arg::DOMAIN => $domain,
        Arg::SECURE => $secure,
        Arg::HTTP_ONLY => $httponly,
        Arg::SAMESITE => $samesite
    ];
}
{'fraction_non_alphanumeric': 0.1697508896797153, 'fraction_numerical': 0.0076512455516014235, 'mean_word_length': 2.2248995983935744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3290551', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1817, 'n_words': 436}