<commit_before><?php

namespace Ornament;

use ReflectionClass;

trait Autoload
{
    /**
     * @onLoad
     */
    public function autoload(array $annotations)
    {
        foreach ($annotations as $property => $anns) {
            if (!isset($this->$property)) {
                continue;
            }
            if (isset($anns['Model'])) {
                $class = $anns['Model'];
                if (isset($anns['Mapping'])) {
                    $maps = $anns['Mapping'];
                } else {
                    $maps = ['id' => $property];
                }
                $ctorargs = [];
                if (isset($anns['Constructor'])) {
                    foreach ($anns['Constructor'] as $arg) {
                        $ctorargs[$arg] = $this->$arg;
                    }
                }
                $ref = new ReflectionClass($class);
                if (!is_array($this->$property)) {
                    $model = $ref->newInstanceArgs($ctorargs);
                    foreach ($maps as $field => $mapto) {
                        $model->$field = $this->$mapto;
                    }
                    $model->load();
                    $this->$property = $model;
                } else {
                    $args = [];
                    foreach ($maps as $key => $arg) {
                        $args[$key] = $this->$arg;
                    }
                    $this->$property = $model->query($args);
                }
            }
        }
    }
}
<commit_msg>we need $model in both cases<commit_after><?php

namespace Ornament;

use ReflectionClass;

trait Autoload
{
    /**
     * @onLoad
     */
    public function autoload(array $annotations)
    {
        foreach ($annotations as $property => $anns) {
            if (!isset($this->$property)) {
                continue;
            }
            if (isset($anns['Model'])) {
                $class = $anns['Model'];
                if (isset($anns['Mapping'])) {
                    $maps = $anns['Mapping'];
                } else {
                    $maps = ['id' => $property];
                }
                $ctorargs = [];
                if (isset($anns['Constructor'])) {
                    foreach ($anns['Constructor'] as $arg) {
                        $ctorargs[$arg] = $this->$arg;
                    }
                }
                $ref = new ReflectionClass($class);
                $model = $ref->newInstanceArgs($ctorargs);
                if (!is_array($this->$property)) {
                    foreach ($maps as $field => $mapto) {
                        $model->$field = $this->$mapto;
                    }
                    $model->load();
                    $this->$property = $model;
                } else {
                    $args = [];
                    foreach ($maps as $key => $arg) {
                        $args[$key] = $this->$arg;
                    }
                    $this->$property = $model->query($args);
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.14862628268785172, 'fraction_numerical': 0.0, 'mean_word_length': 1.0227576974564927, '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': '6153243', 'n_tokens_mistral': 807, 'n_tokens_neox': 754, 'n_words': 143}