Replace the classname and the namespace for the given stub.

@param  string  $name
@param  string  $stub
@return \Rymanalu\FactoryGenerator\Console\MakeCommand
554988
protected function replaceClassAndNamespace($name, &$stub)
    {
        $stub = str_replace(
            ['DummyClassWithNamespace', 'DummyClass'],
            [$this->argument('name'), $name],
            $stub
        );

        return $this;
    }
242406
protected function buildClass($name)
    {
        $stub = $this->files->get($this->getStub());

        $table = $this->option('table') ?: $this->argument('name');
        $fillable = $this->option('fillable');

        return $this->replaceNamespace($stub, $name)
            ->replaceTable($stub, $table)
            ->replaceFillable($stub, $fillable)
            ->replaceClass($stub, $name);
    }
1301955
protected function populateStub($name, $stub, $label)
    {
        $stub = str_replace('DummyClass', studly_case($name), $stub);

        // Here we will replace the label place-holders with the label specified by
        // the developer, which is useful for quickly creating a labels creation
        // or update migration from the console instead of typing it manually.
        if ( ! is_null($label))
        {
            $stub = str_replace('DummyLabel', $label, $stub);
        }

        return $stub;
    }
198896
protected function replaceBaseRepositoryClass(&$stub, $name)
    {
        $baseClass = str_replace($this->getNamespace($name) . '\\', '', $name);
        $stub      = str_replace('BaseRepositoryClass', $baseClass, $stub);

        return $this;
    }
1111537
protected function replaceClass($stub, $name)
    {
        $stub = parent::replaceClass($stub, $name . 'Transformer');
        $stub = str_replace('Dummy', ucfirst($this->argument('name')), $stub);
        $stub = str_replace('dummy', lcfirst($this->argument('name')), $stub);

        if ($this->argument('include')) {
            $stub = str_replace('Item', ucfirst($this->argument('include')), $stub);
            $stub = str_replace('item', lcfirst($this->argument('include')), $stub);
        }

        return $stub;
    }
210326
protected function replaceName(&$stub)
    {
        $stub = str_replace('{{Class}}', $this->scaffoldCommandObj->getObjName('Names'), $stub);
        $stub = str_replace('{{class}}', $this->scaffoldCommandObj->getObjName('names'), $stub);
        $stub = str_replace('{{classSingle}}', $this->scaffoldCommandObj->getObjName('name'), $stub);
        $stub = str_replace('{{ClassSingle}}', $this->scaffoldCommandObj->getObjName('Name'), $stub);

        return $this;
    }
166740
protected function replaceNameStrings(&$stub, $name)
    {
        $table = str_plural(ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_'));

        $stub = str_replace('DummyTable', $table, $stub);
        $stub = str_replace('dummy_class', strtolower(str_replace($this->getNamespace($name).'\\', '', $name)), $stub);

        return $this;
    }
61492
protected function replaceClass($stub, $name)
    {
        $stub = parent::replaceClass($stub, $name);

        return str_replace('DummyModel', '\\'.trim((string) $this->argument('model'), '\\'), $stub);
    }
1054016
protected function buildClass($name)
    {
        $stub = file_get_contents($this->getStub());

        return $this->replaceNamespace($stub, $name)->replaceClass($stub, $name);
    }
106116
protected function replaceNamespace(array $segments, $stub)
	{
		if (count($segments) > 1)
		{
			$namespace = implode('\\', array_slice($segments, 0, -1));

			return str_replace('{{namespace}}', ' namespace '.$namespace.';', $stub);
		}
		else
		{
			return str_replace('{{namespace}}', '', $stub);
		}
	}
804386
protected function replaceSchema(&$stub)
    {
        $tables = $this->getSortedTableNames();
        $stub = str_replace(
            ['{{columnOne}}', '{{columnTwo}}', '{{tableOne}}', '{{tableTwo}}'],
            array_merge(array_map('str_singular', $tables), $tables),
            $stub
        );
        return $this;
    }
871874
protected function buildClass($name)
    {
        $stub = $this->getFiles()->get($this->getCommandDeclaredStubPath());

        return $this->replaceNamespace($stub, $name)
            ->replaceClassNameSingular($stub, $name)
            ->replaceClassNameLowerCase($stub, $name)
            ->replaceClassName($stub, $name)
            ->replaceModuleFolder($stub, $name)
            ->replaceClass($stub, $name)
            
            ->sanitizeStub($stub, $name);
    }
440529
protected function replaceSchema(&$stub)
    {
        if ($schema = $this->scaffoldCommandObj->getMeta()['schema'])
        {
            $schema = (new SchemaParser)->parse($schema);
        }

        $schema = (new SyntaxBuilder)->create($schema, $this->scaffoldCommandObj->getMeta());
        $stub = str_replace(['{{schema_up}}', '{{schema_down}}'], $schema, $stub);
        
        return $this;
    }
491207
protected function replaceModel($stub, $model): string
    {
        $model = str_replace('/', '\\', $model);

        $namespaceModel = $this->rootNamespace().'\Models\\'.$model;

        if (starts_with($model, '\\')) {
            $stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub);
        } else {
            $stub = str_replace('NamespacedDummyModel', $namespaceModel, $stub);
        }

        $stub = str_replace(
            "use {$namespaceModel};\nuse {$namespaceModel};", "use {$namespaceModel};", $stub
        );

        $model = class_basename(trim($model, '\\'));

        $stub = str_replace('DummyModel', $model, $stub);

        return str_replace('dummyModel', camel_case($model), $stub);
    }
290962
protected function replaceConnectionName(&$stub, $name)
    {
        $connectionLine = !empty($name) ? sprintf("connection('%s')->", $name) : '';

        return $this->replaceTemplate('connection_name', $connectionLine, $stub);
    }
201467
protected function replaceSchema(&$stub)
    {
        $schema = '';
        if (!$this->optionPlain()) {
            if ($schema = $this->optionSchema()) {
                $schema = (new SchemaParser)->parse($schema);
            }

            $schema = (new SyntaxBuilder)->create($schema, $this->meta);
        }

        $stub = str_replace(['{{schema_up}}', '{{schema_down}}'], $schema, $stub);

        return $this;
    }
689324
protected function replaceSchema(&$stub)
    {
        if ($schema = $this->option('schema')) {
            $schema = (new SchemaParser)->parse($schema);
        }

        $schema = (new SyntaxBuilder)->create($schema, $this->meta);

        $stub = str_replace(['{{schema_up}}', '{{schema_down}}'], $schema, $stub);

        return $this;
    }