<commit_before><?php

namespace LaravelDoctrine\ORM\Testing;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ManagerRegistry;
use Faker\Generator as Faker;
use Illuminate\Support\Collection;
use InvalidArgumentException;

class FactoryBuilder
{
    /**
     * The model definitions in the container.
     *
     * @var array
     */
    protected $definitions;

    /**
     * The model being built.
     *
     * @var string
     */
    protected $class;

    /**
     * The name of the model being built.
     *
     * @var string
     */
    protected $name = 'default';

    /**
     * The number of models to build.
     *
     * @var int
     */
    protected $amount = 1;

    /**
     * The Faker instance for the builder.
     *
     * @var \Faker\Generator
     */
    protected $faker;

    /**
     * @var ManagerRegistry
     */
    protected $registry;

    /**
     * The model states.
     *
     * @var array
     */
    protected $states = [];

    /**
     * The states to apply.
     *
     * @var array
     */
    protected $activeStates = [];

    /**
     * Create an new builder instance.
     *
     * @param ManagerRegistry  $registry
     * @param string           $class
     * @param string           $name
     * @param array            $definitions
     * @param \Faker\Generator $faker
     * @param array            $afterMaking
     * @param array            $afterCreating
     */
    public function __construct(ManagerRegistry $registry, $class, $name, array $definitions, Faker $faker, array $afterMaking, array $afterCreating)
    {
        $this->name          = $name;
        $this->class         = $class;
        $this->faker         = $faker;
        $this->registry      = $registry;
        $this->definitions   = $definitions;
        $this->afterMaking   = $afterMaking;
        $this->afterCreating = $afterCreating;
    }

    /**
     * Set the amount of models you wish to create / make.
     *
     * @param int $amount
     *
     * @return $this
     */
    public function times($amount)
    {
        $this->amount = $amount;

        return $this;
    }

    /**
     * Create a collection of models and persist them to the database.
     *
     * @param array $attributes
     *
     * @return mixed
     */
    public function create(array $attributes = [])
    {
        $results = $this->make($attributes);
        $manager = $this->registry->getManagerForClass($this->class);

        if ($this->amount === 1) {
            $manager->persist($results);
            $this->callAfterCreating(collect([$results]));
        } else {
            foreach ($results as $result) {
                $manager->persist($result);
            }
            $this->callAfterCreating($results);
        }

        $manager->flush();

        return $results;
    }

    /**
     * @param ManagerRegistry $registry
     * @param string          $class
     * @param string          $name
     * @param array           $definitions
     * @param Faker           $faker
     * @param array           $states
     * @param array           $afterMaking
     * @param array           $afterCreating
     *
     * @return FactoryBuilder
     */
    public static function construct(
        ManagerRegistry $registry,
        $class,
        $name,
        array $definitions,
        Faker $faker,
        array $states,
        array $afterMaking = [],
        array $afterCreating = []
    )
    {
        $instance         = new static($registry, $class, $name, $definitions, $faker, $afterMaking, $afterCreating);
        $instance->states = $states;

        return $instance;
    }

    /**
     * Create a collection of models.
     *
     * @param array $attributes
     *
     * @return mixed
     */
    public function make(array $attributes = [])
    {
        if ($this->amount === 1) {
            return tap($this->makeInstance($attributes), function ($instance) {
                $this->callAfterMaking(collect([$instance]));
            });
        } else {
            $results = [];<commit_msg>Apply fixes from StyleCI<commit_after><?php

namespace LaravelDoctrine\ORM\Testing;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ManagerRegistry;
use Faker\Generator as Faker;
use Illuminate\Support\Collection;
use InvalidArgumentException;

class FactoryBuilder
{
    /**
     * The model definitions in the container.
     *
     * @var array
     */
    protected $definitions;

    /**
     * The model being built.
     *
     * @var string
     */
    protected $class;

    /**
     * The name of the model being built.
     *
     * @var string
     */
    protected $name = 'default';

    /**
     * The number of models to build.
     *
     * @var int
     */
    protected $amount = 1;

    /**
     * The Faker instance for the builder.
     *
     * @var \Faker\Generator
     */
    protected $faker;

    /**
     * @var ManagerRegistry
     */
    protected $registry;

    /**
     * The model states.
     *
     * @var array
     */
    protected $states = [];

    /**
     * The states to apply.
     *
     * @var array
     */
    protected $activeStates = [];

    /**
     * Create an new builder instance.
     *
     * @param ManagerRegistry  $registry
     * @param string           $class
     * @param string           $name
     * @param array            $definitions
     * @param \Faker\Generator $faker
     * @param array            $afterMaking
     * @param array            $afterCreating
     */
    public function __construct(ManagerRegistry $registry, $class, $name, array $definitions, Faker $faker, array $afterMaking, array $afterCreating)
    {
        $this->name          = $name;
        $this->class         = $class;
        $this->faker         = $faker;
        $this->registry      = $registry;
        $this->definitions   = $definitions;
        $this->afterMaking   = $afterMaking;
        $this->afterCreating = $afterCreating;
    }

    /**
     * Set the amount of models you wish to create / make.
     *
     * @param int $amount
     *
     * @return $this
     */
    public function times($amount)
    {
        $this->amount = $amount;

        return $this;
    }

    /**
     * Create a collection of models and persist them to the database.
     *
     * @param array $attributes
     *
     * @return mixed
     */
    public function create(array $attributes = [])
    {
        $results = $this->make($attributes);
        $manager = $this->registry->getManagerForClass($this->class);

        if ($this->amount === 1) {
            $manager->persist($results);
            $this->callAfterCreating(collect([$results]));
        } else {
            foreach ($results as $result) {
                $manager->persist($result);
            }
            $this->callAfterCreating($results);
        }

        $manager->flush();

        return $results;
    }

    /**
     * @param ManagerRegistry $registry
     * @param string          $class
     * @param string          $name
     * @param array           $definitions
     * @param Faker           $faker
     * @param array           $states
     * @param array           $afterMaking
     * @param array           $afterCreating
     *
     * @return FactoryBuilder
     */
    public static function construct(
        ManagerRegistry $registry,
        $class,
        $name,
        array $definitions,
        Faker $faker,
        array $states,
        array $afterMaking = [],
        array $afterCreating = []
    ) {
        $instance         = new static($registry, $class, $name, $definitions, $faker, $afterMaking, $afterCreating);
        $instance->states = $states;

        return $instance;
    }

    /**
     * Create a collection of models.
     *
     * @param array $attributes
     *
     * @return mixed
     */
    public function make(array $attributes = [])
    {
        if ($this->amount === 1) {
            return tap($this->makeInstance($attributes), function ($instance) {
                $this->callAfterMaking(collect([$instance]));
            });
        } else {
            $results = [];
{'fraction_non_alphanumeric': 0.12068338785896038, 'fraction_numerical': 0.0007270083605961468, 'mean_word_length': 1.6991497710922172, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '2989381', 'n_tokens_mistral': 2326, 'n_tokens_neox': 2248, 'n_words': 573}