<commit_before><?php
declare(strict_types=1);

namespace LotGD\Core\Tools\Model;

/**
 * Provides method and doctrine annotation for a property submodel
 */
trait PropertyManager
{
    private $propertyStorage = null;

    public function loadProperties()
    {
        if ($this->propertyStorage !== null) {
            return;
        }

        foreach ($this->properties as $property) {
            $this->propertyStorage[$property->getName()] = $property;
        }
    }

    public function getProperty(string $name, $default = null)
    {
        $this->loadProperties();

        if (isset($this->propertyStorage[$name])) {
            return $this->propertyStorage[$name]->getValue();
        } else {
            return $default;
        }
    }

    public function setProperty(string $name, $value)
    {
        $this->loadProperties();

        if (isset($this->propertyStorage[$name])) {
            $this->propertyStorage[$name]->setValue($value);
        } else {
            $className = $this->properties->getTypeClass()->name;
            $property = new $className();
            if (method_exists($property, "setOwner")) {
                $property->setOwner($this);
            }
            $property->setName($name);
            $property->setValue($value);

            $this->propertyStorage[$name] = $property;
            $this->properties->add($property);
        }
    }
}
<commit_msg>Add unsetProperty for property managers<commit_after><?php
declare(strict_types=1);

namespace LotGD\Core\Tools\Model;

/**
 * Provides method and doctrine annotation for a property submodel
 */
trait PropertyManager
{
    private $propertyStorage = null;

    public function loadProperties()
    {
        if ($this->propertyStorage !== null) {
            return;
        }

        foreach ($this->properties as $property) {
            $this->propertyStorage[$property->getName()] = $property;
        }
    }

    public function getProperty(string $name, $default = null)
    {
        $this->loadProperties();

        if (isset($this->propertyStorage[$name])) {
            return $this->propertyStorage[$name]->getValue();
        } else {
            return $default;
        }
    }

    public function unsetProperty(string $name)
    {
        $this->loadProperties();

        if (isset($this->propertyStorage[$name])) {
            $property = $this->propertyStorage[$name];
            $this->properties->removeElement($property);
            unset($this->propertyStorage[$name]);
        }
    }

    public function setProperty(string $name, $value)
    {
        $this->loadProperties();

        if (isset($this->propertyStorage[$name])) {
            $this->propertyStorage[$name]->setValue($value);
        } else {
            $className = $this->properties->getTypeClass()->name;
            $property = new $className();
            if (method_exists($property, "setOwner")) {
                $property->setOwner($this);
            }
            $property->setName($name);
            $property->setValue($value);

            $this->propertyStorage[$name] = $property;
            $this->properties->add($property);
        }
    }
}

{'fraction_non_alphanumeric': 0.1459578483799937, 'fraction_numerical': 0.0006291286568103177, 'mean_word_length': 2.202416918429003, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '4314735', 'n_tokens_mistral': 826, 'n_tokens_neox': 818, 'n_words': 153}