<commit_before><?php namespace App\Services;

use App\Http\Transformers\BaseTransformer;
use Illuminate\Container\Container;
use Illuminate\Support\Facades\App;

class ModelFactory
{

    protected $factory;

    /**
     * Initialise the factory
     */
    public function __construct()
    {
        $this->factory = Container::getInstance()->make('Illuminate\Database\Eloquent\Factory');
    }

    /**
     * Get a model factory entity. e.g. $factory->make(\App\Models\User::class, 1, ['email'=>'<EMAIL>'])
     * @param $factoryName
     * @param int $count
     * @param array $overrides
     * @return mixed
     */
    public function make($factoryName, $count = 1, $overrides = [])
    {

        $factoryInstance = null;
        if (is_array($factoryName)){
            $factoryInstance = $this->factory->of($factoryName[0], $factoryName[1]);
        }else{
            $factoryInstance = $this->factory->of($factoryName);
        }

        return $factoryInstance->times($count)->make($overrides);
    }
    /**
     * Get a model factory entity as a json string
     * @param $factoryName
     * @param int $count
     * @param array $overrides
     * @param array $properties white/blacklist of properties e.g. ['email'] will only show the email, ['password'] will hide the password if $blacklistProperties is true
     * @param bool $blacklistProperties
     * @return string
     */
    public function json($factoryName, $count = 1, $overrides = [], $properties = [], $blacklistProperties = false)
    {

        $entity = $this->make($factoryName, $count, $overrides, $properties);

        $transformerService = App::make('App\Services\Transformer');

        $entityType = ($count > 1) ? 'collection' : 'item';

        $transformedEntity = $transformerService->{$entityType}($entity, new BaseTransformer);

        if (!empty($properties)){
            switch($entityType){
                case 'collection':
                {
                    $transformedEntity = array_map(function($entity) use ($properties, $blacklistProperties){
                        return $blacklistProperties ? array_except($entity, $properties) : array_only($entity, $properties);
                    }, $transformedEntity);
                }
                    break;

                case 'item':
                default:
                    $transformedEntity = $blacklistProperties ? array_except($entity, $properties) : array_only($entity, $properties);
            }

            dd($properties, $transformedEntity);
        }




        return json_encode($transformedEntity, JSON_PRETTY_PRINT);
    }

}<commit_msg>Updated user entity to have a userType, added tests for the model factory to have full unit test coverage<commit_after><?php namespace App\Services;

use App\Http\Transformers\BaseTransformer;
use Illuminate\Container\Container;
use Illuminate\Support\Facades\App;

class ModelFactory
{

    protected $factory;

    /**
     * Initialise the factory
     */
    public function __construct()
    {
        $this->factory = Container::getInstance()->make('Illuminate\Database\Eloquent\Factory');
    }

    /**
     * Get a model factory entity. e.g. $factory->make(\App\Models\User::class, 1, ['email'=>'<EMAIL>'])
     * @param $factoryName
     * @param int $count
     * @param array $overrides
     * @return mixed
     */
    public function make($factoryName, $count = 1, $overrides = [])
    {

        $factoryInstance = null;
        if (is_array($factoryName)){
            $factoryInstance = $this->factory->of($factoryName[0], $factoryName[1]);
        }else{
            $factoryInstance = $this->factory->of($factoryName);
        }

        return $factoryInstance->times($count)->make($overrides);
    }
    /**
     * Get a model factory entity as a json string
     * @param $factoryName
     * @param int $count
     * @param array $overrides
     * @param array $properties white/blacklist of properties e.g. ['email'] will only show the email, ['password'] will hide the password if $blacklistProperties is true
     * @param bool $blacklistProperties
     * @return string
     */
    public function json($factoryName, $count = 1, $overrides = [], $properties = [], $blacklistProperties = false)
    {

        $entity = $this->make($factoryName, $count, $overrides, $properties);

        $transformerService = App::make('App\Services\Transformer');

        $entityType = ($count > 1) ? 'collection' : 'item';

        $transformedEntity = $transformerService->{$entityType}($entity, new BaseTransformer);

        if (!empty($properties)){
            switch($entityType){
                case 'collection':
                {
                    $transformedEntity = array_map(function($entity) use ($properties, $blacklistProperties){
                        return $blacklistProperties ? array_except($entity, $properties) : array_only($entity, $properties);
                    }, $transformedEntity);
                }
                    break;

                case 'item':
                default:
                    $transformedEntity = $blacklistProperties ? array_except($transformedEntity, $properties) : array_only($transformedEntity, $properties);
            }

        }



        return json_encode($transformedEntity, JSON_PRETTY_PRINT);
    }

}
{'fraction_non_alphanumeric': 0.12951127819548872, 'fraction_numerical': 0.002255639097744361, 'mean_word_length': 2.5098944591029024, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, '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': '5810361', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1391, 'n_words': 334}