Finding multi location stub

@param $stubName
@return string
162417
public function findingStub($stubName)
    {
        $stubRoots = $this->config->get('tie.stubs.path');
        foreach ($stubRoots as $stubRoot) {
            $stub = $stubRoot . '/' . $stubName . '.stub';
            if ($this->filesystem->exists($stub)) {
                return $stub;
            }
        }

        return '';
    }
337722
protected function getStub()
	{
		if ($this->option('queued') && $this->option('handler'))
		{
			return __DIR__.'/stubs/command-queued-with-handler.stub';
		}
		elseif ($this->option('queued'))
		{
			return __DIR__.'/stubs/command-queued.stub';
		}
		elseif ($this->option('handler'))
		{
			return __DIR__.'/stubs/command-with-handler.stub';
		}
		else
		{
			return __DIR__.'/stubs/command.stub';
		}
	}
831203
public function stub($property = null, $value = null) {
		if ($property === null) {
			return $this->_stub;
		}
		if ($value === null) {
			return isset($this->_stub[$property]) ? $this->_stub[$property] : null;
		}
		if (!empty($property) && !empty($value)) {
			$this->_stub[$property] = $value;
		}
		return $this;
	}
686171
protected function getJsonStubPath()
    {
        $stubPath = $this->laravel->make('config')->get('laravel-widgets.widget_json_stub');

        return $this->laravel->basePath() . '/' . $stubPath;
    }
211116
protected function replaceModel($stub, $model)
    {
        $model = str_replace('/', '\\', $model);

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

        if (Str::startsWith($model, '\\')) {
            $stub = str_replace('{{fullModel}}', trim($model, '\\'), $stub);
        } else {
            $stub = str_replace('{{fullModel}}', $namespaceModel, $stub);
        }

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

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

        $stub = str_replace('{{model}}', $model, $stub);

        $stub = str_replace('{{camelModel}}', Str::camel($model), $stub);

        return str_replace('{{pluralModel}}', Str::plural(Str::camel($model)), $stub);
    }
1147001
public function getStub()
    {
        $parser = $this->getNameParser();

        $action = $parser->getAction();
        switch ($action) {
            case 'add':
            case 'append':
            case 'update':
            case 'insert':
                $file = 'change';
                $replacements = [
                    'class'       => $this->getClass(),
                    'table'       => $parser->getTable(),
                    'fields_up'   => $this->getSchemaParser()->up(),
                    'fields_down' => $this->getSchemaParser()->down(),
                ];
                break;

            case 'delete':
            case 'remove':
            case 'alter':
                $file = 'change';
                $replacements = [
                    'class'       => $this->getClass(),
                    'table'       => $parser->getTable(),
                    'fields_down' => $this->getSchemaParser()->up(),
                    'fields_up'   => $this->getSchemaParser()->down(),
                ];
                break;
            default:
                $file = 'create';
                $replacements = [
                    'class'  => $this->getClass(),
                    'table'  => $parser->getTable(),
                    'fields' => $this->getSchemaParser()->up(),
                ];
                break;
        }
        $path = config('repository.generator.stubsOverridePath', __DIR__);

        if (!file_exists($path . "/Stubs/migration/{$file}.stub")) {
            $path = __DIR__;
        }

        if (!file_exists($path . "/Stubs/migration/{$file}.stub")) {
            throw new FileNotFoundException($path . "/Stubs/migration/{$file}.stub");
        }

        return Stub::create($path . "/Stubs/migration/{$file}.stub", $replacements);
    }
995160
protected function getDateFields($stub, array $fields)
    {
        $dates = [];
        $indentCount = $this->getIndent($stub, $this->getTemplateVariable('dates'));
        $indent = $this->Indent($indentCount - $this->backspaceCount);
        foreach ($fields as $field) {
            if ($field->isDate) {
                $dates[] = sprintf("%s'%s'", $indent, $field->name);
            }
        }

        return $this->makeArrayString($dates, $indentCount - $this->backspaceCount - 4);
    }
1092565
protected function getCasts($stub, array $fields)
    {
        $casts = [];
        $indentCount = $this->getIndent($stub, $this->getTemplateVariable('casts'));
        $indent = $this->Indent($indentCount - $this->backspaceCount);
        foreach ($fields as $field) {
            if ($field->isCastable()) {
                $casts[$field->name] = sprintf("%s'%s' => '%s'", $indent, $field->name, $field->castAs);
            }
        }

        return $this->makeArrayString($casts, $indentCount - $this->backspaceCount - 4);
    }
998396
protected function formatStub($stub, array $replacement)
    {
        foreach ($replacement as $src => $dest) {
            $stub = str_replace($src, $dest, $stub);
        }
        return $stub;
    }
1351399
protected function getStub()
    {
        $stub = null;

        if ($this->option('parent')) {
            $stub = '/stubs/controller.nested.stub';
        } elseif ($this->option('model')) {
            $stub = '/stubs/controller.model.stub';
        } elseif ($this->option('invokable')) {
            $stub = '/stubs/controller.invokable.stub';
        } elseif ($this->option('resource')) {
            $stub = '/stubs/controller.stub';
        }

        $stub = $stub ?? '/stubs/controller.plain.stub';

        return __DIR__ . $stub;
    }
781631
protected function replaceClass($stub, $name)
    {
        $stub = str_replace('{{class}}',$this->parseName($name), $stub);
        return $stub;
    }
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);
    }
1034397
public function getStub()
    {
        if ($this->plain) {
            return $this->getPath();
        }

        if ($template = $this->template) {
            return Stub::create($template, $this->getReplacements())->render();
        }

        return parent::getStub();
    }
313334
protected function replaceNamespace(string $stub):string
    {
        if (method_exists($this->laravel, 'getNameSpace')) {
            $namespace = $this->laravel->getNamespace() . 'Transformers';
        } else {
            $namespace = 'App\Transformers';
        }

        $stub = str_replace('DummyNamespace', $namespace, $stub);

        return $stub;
    }
542710
protected function formatFacadeStub($alias, $stub)
    {
        $replacements = [
            str_replace('/', '\\', dirname(str_replace('\\', '/', $alias))),
            class_basename($alias),
            substr($alias, strlen(static::$facadeNamespace)),
        ];

        return str_replace(
            ['DummyNamespace', 'DummyClass', 'DummyTarget'], $replacements, $stub
        );
    }
290962
protected function replaceConnectionName(&$stub, $name)
    {
        $connectionLine = !empty($name) ? sprintf("connection('%s')->", $name) : '';

        return $this->replaceTemplate('connection_name', $connectionLine, $stub);
    }
1316391
protected function replaceModel($stub, $model)
    {
        $model = str_replace('/', '\\', $model);

        $namespaceModel =
            trim($this->laravel->getNamespace(), '\\')
            . $this->getModuleNamespace()
            . config('stubs.namespaces.model') . '\\'
            . $model;

        if (Str::startsWith($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, '\\'));
        $dummyUser = class_basename(config('auth.providers.users.model'));
        $dummyModel = Str::camel($model) === 'user' ? 'model' : Str::camel($model);

        $stub = str_replace('DummyModel', $model, $stub);
        $stub = str_replace('dummyModel', $dummyModel, $stub);
        $stub = str_replace('DummyUser', $dummyUser, $stub);

        return str_replace('dummyPluralModel', Str::plural($dummyModel), $stub);
    }