<commit_before><?php

namespace Structr\Tree\Composite;

use Structr\Tree\Base\PrototypeNode;

use Structr\Exception;

class MapKeyNode extends PrototypeNode
{
    private $_required = true;
    private $_optional = false;
    private $_defaultValue = null;

    private $_name;

    public function setName($name) {
        $this->_name = $name;
    }

    public function getName() {
        return $this->_name;
    }

    public function defaultValue($value) {
        $this->_required = false;
        $this->_defaultValue = $value;

        return $this;
    }

    public function optional() {
        $this->_optional = true;

        return $this;
    }

    public function isOptional() {
        return $this->_optional;
    }

    public function endKey() {
        return $this->parent();
    }

    public function _walk_value_unset() {
        if ($this->_required) {
            throw new Exception("Missing key '{$this->_name}'");
        }

        return $this->_defaultValue;
    }
}
<commit_msg>Add optional parameter to optional()<commit_after><?php

namespace Structr\Tree\Composite;

use Structr\Tree\Base\PrototypeNode;

use Structr\Exception;

class MapKeyNode extends PrototypeNode
{
    private $_required = true;
    private $_optional = false;
    private $_defaultValue = null;

    private $_name;

    public function setName($name) {
        $this->_name = $name;
    }

    public function getName() {
        return $this->_name;
    }

    public function defaultValue($value) {
        $this->_required = false;
        $this->_defaultValue = $value;

        return $this;
    }

    public function optional($optional = true) {
        $this->_optional = $optional;

        return $this;
    }

    public function isOptional() {
        return $this->_optional;
    }

    public function endKey() {
        return $this->parent();
    }

    public function _walk_value_unset() {
        if ($this->_required) {
            throw new Exception("Missing key '{$this->_name}'");
        }

        return $this->_defaultValue;
    }
}

{'fraction_non_alphanumeric': 0.11801541425818883, 'fraction_numerical': 0.0, 'mean_word_length': 2.355411954765751, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '6020798', 'n_tokens_mistral': 599, 'n_tokens_neox': 580, 'n_words': 145}