<commit_before><?php

namespace Ornament\Core;

use zpt\anno\Annotations;
use ReflectionClass;
use ReflectionProperty;
use ReflectionException;
use SplObjectStorage;
use StdClass;
use Error;
use Traversable;

/**
 * `use` this trait to turn any vanilla class into an Ornament model.
 */
trait Model
{
    /**
     * @var object
     *
     * Private storage of the model's initial state.
     */
    private $__initial;

    /**
     * @var callable
     */
    private static $arrayToModelTransformer;

    /**
     * Constructor.
     *
     * @param iterable|null $input
     * @return void
     */
    public function __construct(iterable $input = null)
    {
        $cache = $this->__getModelPropertyDecorations();
        foreach ($cache['properties'] as $field => $annotations) {
            $this->$field = $this->ornamentalize($field, $this->$field ?? null);
        }
        if (isset($input)) {
            foreach ($input as $key => $value) {
                $this->$key = $this->ornamentalize($key, $value);
            }
        }
        $this->__initial = clone $this;
    }<commit_msg>this initialization should only be done if a property was actually decorated<commit_after><?php

namespace Ornament\Core;

use zpt\anno\Annotations;
use ReflectionClass;
use ReflectionProperty;
use ReflectionException;
use SplObjectStorage;
use StdClass;
use Error;
use Traversable;

/**
 * `use` this trait to turn any vanilla class into an Ornament model.
 */
trait Model
{
    /**
     * @var object
     *
     * Private storage of the model's initial state.
     */
    private $__initial;

    /**
     * @var callable
     */
    private static $arrayToModelTransformer;

    /**
     * Constructor.
     *
     * @param iterable|null $input
     * @return void
     */
    public function __construct(iterable $input = null)
    {
        $cache = $this->__getModelPropertyDecorations();
        foreach ($cache['properties'] as $field => $annotations) {
            $reflection = new ReflectionProperty($this, $field);
            $decorated = $this->ornamentalize($field, $this->$field ?? null);
            if (is_object($decorated)) {
                $this->$field = $decorated;
            }
        }
        if (isset($input)) {
            foreach ($input as $key => $value) {
                $this->$key = $this->ornamentalize($key, $value);
            }
        }
        $this->__initial = clone $this;
    }
{'fraction_non_alphanumeric': 0.12705592105263158, 'fraction_numerical': 0.0, 'mean_word_length': 2.287837837837838, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '1145278', 'n_tokens_mistral': 722, 'n_tokens_neox': 707, 'n_words': 187}