<commit_before><?php
namespace ANavallaSuiza\Crudoado\Abstractor\Eloquent;

use ANavallaSuiza\Crudoado\Contracts\Abstractor\ModelFactory as ModelAbstractorFactoryContract;
use ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager;
use EasySlugger\Slugger;

class ModelFactory implements ModelAbstractorFactoryContract
{
    protected $modelManager;
    protected $slugger;

    protected $allConfiguredModels;

    public function __construct(array $allConfiguredModels, ModelManager $modelManager)
    {
        $this->allConfiguredModels = $allConfiguredModels;
        $this->modelManager = $modelManager;
        $this->slugger = new Slugger();
    }

    public function getBySlug($slug, $id = null)
    {
        $model = null;

        foreach ($this->allConfiguredModels as $modelName => $config) {
            $modelSlug = $this->slugger->slugify($modelName);

            if ($modelSlug === $slug) {
                if (is_array($config)) {
                    $modelNamespace = $config['model'];
                } else {
                    $modelNamespace = $config;
                }

                $model = new Model($config, $this->modelManager->getAbstractionLayer($modelNamespace));

                $model->setSlug($modelSlug)
                    ->setName($modelName);

                if (is_null($id)) {
                    $model->setInstance($this->modelManager->getModelInstance($modelNamespace));
                } else {
                    $repository = $this->modelManager->getRepository($modelNamespace);
                    $model->setInstance($repository->findByOrFail($repository->getModel()->getKeyName(), $id));<commit_msg>relation factory<commit_after><?php
namespace ANavallaSuiza\Crudoado\Abstractor\Eloquent;

use ANavallaSuiza\Crudoado\Contracts\Abstractor\ModelFactory as ModelAbstractorFactoryContract;
use ANavallaSuiza\Crudoado\Contracts\Abstractor\RelationFactory as RelationAbstractorFactoryContract;
use ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager;
use EasySlugger\Slugger;

class ModelFactory implements ModelAbstractorFactoryContract
{
    protected $modelManager;
    protected $relationFactory;
    protected $slugger;

    protected $allConfiguredModels;

    public function __construct(array $allConfiguredModels, ModelManager $modelManager, RelationAbstractorFactoryContract $relationFactory)
    {
        $this->allConfiguredModels = $allConfiguredModels;
        $this->modelManager = $modelManager;
        $this->relationFactory = $relationFactory;
        $this->slugger = new Slugger();
    }

    public function getBySlug($slug, $id = null)
    {
        $model = null;

        foreach ($this->allConfiguredModels as $modelName => $config) {
            $modelSlug = $this->slugger->slugify($modelName);

            if ($modelSlug === $slug) {
                if (is_array($config)) {
                    $modelNamespace = $config['model'];
                } else {
                    $modelNamespace = $config;
                }

                $model = new Model($config, $this->modelManager->getAbstractionLayer($modelNamespace), $this->relationFactory);

                $model->setSlug($modelSlug)
                    ->setName($modelName);

                if (is_null($id)) {
                    $model->setInstance($this->modelManager->getModelInstance($modelNamespace));
                } else {
                    $repository = $this->modelManager->getRepository($modelNamespace);
                    $model->setInstance($repository->findByOrFail($repository->getModel()->getKeyName(), $id));
{'fraction_non_alphanumeric': 0.11478599221789883, 'fraction_numerical': 0.0, 'mean_word_length': 2.733402489626556, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '2965729', 'n_tokens_mistral': 992, 'n_tokens_neox': 952, 'n_words': 155}