Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alternative way to provide the namespace via configuration #776

Merged
merged 3 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Commands/CommandMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class CommandMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.command.path', 'Console');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.command.namespace'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why catching this in a namespace variable? I think you can use ?: instead. In order to have it fit on one line this can be done:

    public function getDefaultNamespace() : string
    {
        $module = $this->laravel['modules'];

        $namespace = $module->config('paths.generator.command.namespace');
        
        return $namespace ?: $module->config('paths.generator.command.path', 'Console');
    }

(same for all)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy will add unit and some changes on it

? $namespace
: $module->config('paths.generator.command.path', 'Console');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/ControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ private function getControllerNameWithoutNamespace()

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.controller.path', 'Http/Controllers');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.controller.namespace'))
? $namespace
: $module->config('paths.generator.controller.path', 'Http/Controllers');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/EventMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ protected function getFileName()

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.event.path', 'Events');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.event.namespace'))
? $namespace
: $module->config('paths.generator.event.path', 'Events');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/JobMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class JobMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.jobs.path', 'Jobs');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.jobs.namespace'))
? $namespace
: $module->config('paths.generator.jobs.path', 'Jobs');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/MailMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class MailMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.emails.path', 'Emails');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.emails.namespace'))
? $namespace
: $module->config('paths.generator.emails.path', 'Emails');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/MiddlewareMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class MiddlewareMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.filter.path', 'Http/Middleware');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.filter.namespace'))
? $namespace
: $module->config('paths.generator.filter.path', 'Http/Middleware');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ private function getFillable()
*/
public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.model.path', 'Entities');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.model.namespace'))
? $namespace
: $module->config('paths.generator.model.path', 'Entities');
}
}
6 changes: 5 additions & 1 deletion src/Commands/NotificationMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ final class NotificationMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.notifications.path', 'Notifications');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.notifications.namespace'))
? $namespace
: $module->config('paths.generator.notifications.path', 'Notifications');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/PolicyMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class PolicyMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.policies.path', 'Policies');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.policies.namespace'))
? $namespace
: $module->config('paths.generator.policies.path', 'Policies');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/ProviderMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class ProviderMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.provider.path', 'Providers');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.provider.namespace'))
? $namespace
: $module->config('paths.generator.provider.path', 'Providers');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/RequestMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class RequestMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.request.path', 'Http/Requests');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.request.namespace'))
? $namespace
: $module->config('paths.generator.request.path', 'Http/Requests');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/ResourceMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class ResourceMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.resource.path', 'Transformers');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.resource.namespace'))
? $namespace
: $module->config('paths.generator.resource.path', 'Transformers');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/RouteProviderMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ protected function getApiRoutesPath()

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.provider.path', 'Providers');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.provider.namespace'))
? $namespace
: $module->config('paths.generator.provider.path', 'Providers');
}
}
6 changes: 5 additions & 1 deletion src/Commands/RuleMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class RuleMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.rules.path', 'Rules');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.rules.namespace'))
? $namespace
: $module->config('paths.generator.rules.path', 'Rules');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/SeedMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ private function getSeederName()
*/
public function getDefaultNamespace() : string
{
return $this->laravel['modules']->config('paths.generator.seeder.path', 'Database/Seeders');
$module = $this->laravel['modules'];

return ($namespace = $module->config('paths.generator.seeder.namespace'))
? $namespace
: $module->config('paths.generator.seeder.path', 'Database/Seeders');
}
}
11 changes: 9 additions & 2 deletions src/Commands/TestMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ class TestMakeCommand extends GeneratorCommand

public function getDefaultNamespace() : string
{
$module = $this->laravel['modules'];

if ($this->option('feature')) {
return $this->laravel['modules']->config('paths.generator.test-feature.path', 'Tests/Feature');
return ($namespace = $module->config('paths.generator.test-feature.namespace'))
? $namespace
: $module->config('paths.generator.test-feature.path', 'Tests/Feature');
}
return $this->laravel['modules']->config('paths.generator.test.path', 'Tests/Unit');

return ($namespace = $module->config('paths.generator.test.namespace'))
? $namespace
: $module->config('paths.generator.test.path', 'Tests/Unit');
}

/**
Expand Down