<commit_before><?php

namespace Bootlace\Http\Response\Cookie;

/**
 * Class CookieBuilder
 *
 * @package Bootlace\Http
 */
class CookieBuilder implements CookieBuilderInterface
{
    /* @var string $defaultDomain */
    private $defaultDomain = '';

    /* @var string $defaultPath */
    private $defaultPath = '/';

    /* @var bool $defaultSecure */
    private $defaultSecure = true;

    /* @var bool $defaultHttpOnly */
    private $defaultHttpOnly = true;

    /**
     * Sets the default Cookie domain property.
     *
     * @param string $domain
     * @return CookieBuilderInterface
     */
    public function setDefaultDomain(string $domain): CookieBuilderInterface
    {
        $this->defaultDomain = $domain;
        return $this;
    }

    /**
     * Sets the default Cookie path property.
     *
     * @param string $path
     * @return CookieBuilderInterface
     */
    public function setDefaultPath(string $path): CookieBuilderInterface
    {
        $this->defaultPath = $path;
        return $this;
    }

    /**
     * Sets the default Cookie secure property.
     * @param bool $secure
     * @return CookieBuilderInterface
     */
    public function setDefaultSecure(bool $secure): CookieBuilderInterface
    {
        $this->defaultSecure = $secure;
        return $this;
    }

    /**
     * Sets the default Cookie HttpOnly property.
     * @param bool $httpOnly
     * @return CookieBuilderInterface
     */
    public function setDefaultHttpOnly(bool $httpOnly): CookieBuilderInterface
    {
        $this->defaultHttpOnly = $httpOnly;
        return $this;
    }

    /**
     * Build a new Cookie.
     *
     * @param string $name
     * @param string $value
     * @return CookieInterface
     */
    public function build(string $name, string $value): CookieInterface
    {
        $cookie = new Cookie($name, $value);
        $cookie->setPath($this->defaultPath);
        $cookie->setSecure($this->defaultSecure);
        $cookie->setHttpOnly($this->defaultHttpOnly);
        if ($this->defaultDomain !== null) {
            $cookie->setDomain($this->defaultDomain);
        }
        return $cookie;
    }
}<commit_msg>Add default maxAge to CookieBuilder.<commit_after><?php

namespace Bootlace\Http\Response\Cookie;

/**
 * Class CookieBuilder
 *
 * @package Bootlace\Http
 */
class CookieBuilder implements CookieBuilderInterface
{
    /* @var string $defaultDomain */
    private $defaultDomain = '';

    /* @var string $defaultPath */
    private $defaultPath = '/';

    /* @var bool $defaultSecure */
    private $defaultSecure = true;

    /* @var bool $defaultHttpOnly */
    private $defaultHttpOnly = true;

    /* @var int $maxAge */
    private $maxAge;

    public function __construct()
    {
        $this->maxAge = time() + 3600;
    }

    /**
     * Sets the default Cookie domain property.
     *
     * @param string $domain
     * @return CookieBuilderInterface
     */
    public function setDefaultDomain(string $domain): CookieBuilderInterface
    {
        $this->defaultDomain = $domain;
        return $this;
    }

    /**
     * Sets the default Cookie path property.
     *
     * @param string $path
     * @return CookieBuilderInterface
     */
    public function setDefaultPath(string $path): CookieBuilderInterface
    {
        $this->defaultPath = $path;
        return $this;
    }

    /**
     * Sets the default Cookie secure property.
     * @param bool $secure
     * @return CookieBuilderInterface
     */
    public function setDefaultSecure(bool $secure): CookieBuilderInterface
    {
        $this->defaultSecure = $secure;
        return $this;
    }

    /**
     * Sets the default Cookie HttpOnly property.
     * @param bool $httpOnly
     * @return CookieBuilderInterface
     */
    public function setDefaultHttpOnly(bool $httpOnly): CookieBuilderInterface
    {
        $this->defaultHttpOnly = $httpOnly;
        return $this;
    }

    /**
     * Sets the default Cookie MaxAge property.
     *
     * @param mixed $maxAge
     * @return CookieBuilderInterface
     */
    public function setDefaultMaxAge(int $maxAge): CookieBuilderInterface
    {
        $this->maxAge = $maxAge;
        return $this;
    }

    /**
     * Build a new Cookie.
     *
     * @param string $name
     * @param string $value
     * @return CookieInterface
     */
    public function build(string $name, string $value): CookieInterface
    {
        $cookie = new Cookie($name, $value);
        $cookie->setPath($this->defaultPath);
        $cookie->setSecure($this->defaultSecure);
        $cookie->setHttpOnly($this->defaultHttpOnly);
        $cookie->setMaxAge($this->maxAge);
        if ($this->defaultDomain !== null) {
            $cookie->setDomain($this->defaultDomain);
        }
        return $cookie;
    }
}
{'fraction_non_alphanumeric': 0.11501663893510815, 'fraction_numerical': 0.0008319467554076539, 'mean_word_length': 2.3771067415730336, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '7546896', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1299, 'n_words': 326}