Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 authored and github-actions[bot] committed Jun 5, 2024
1 parent 19add13 commit f4558cb
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 76 deletions.
24 changes: 12 additions & 12 deletions src/Commands/ControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function getTemplateContents(): string
'MESSAGE_VARIABLE' => Str::title(Str::replace('-', ' ', Str::kebab($this->getResourceVariableName()))),
'RESOURCE_NAMESPACES' => '',
'REQUEST_NAMESPACES' => '',
'MODEL' => str_replace('/', '\\', $this->getDefaultNamespace('model') . '\\' . $this->option('model')),
'MODEL' => str_replace('/', '\\', $this->getDefaultNamespace('model').'\\'.$this->option('model')),
'STORE_REQUEST' => '',
'UPDATE_REQUEST' => '',
'INDEX_REQUEST' => '',
Expand Down Expand Up @@ -113,33 +113,33 @@ protected function getResourceVariableName()

protected function getClassPath(string $prefix = '', string $suffix = 'Request')
{
$resourcePath = $this->argument('name') . $suffix;
$resourcePath = $this->argument('name').$suffix;

$dir = dirname($resourcePath);

$dir = ($dir == '.') ? '' : $dir . '/';
$dir = ($dir == '.') ? '' : $dir.'/';

$resource = basename($resourcePath);

return $dir . $prefix . $resource;
return $dir.$prefix.$resource;
}

private function setRequestNamespaces(array &$replacements)
{
$namespaces = [];

foreach (['Store', 'Update', 'Index'] as $prefix) {
$path = $this->getModuleName() . '/'
. $this->getDefaultNamespace('request') . '/'
. dirname($this->option('model')) . '/' . $prefix . class_basename($this->option('model')) . 'Request';
$path = $this->getModuleName().'/'
.$this->getDefaultNamespace('request').'/'
.dirname($this->option('model')).'/'.$prefix.class_basename($this->option('model')).'Request';

match ($prefix) {
'Store' => $replacements['STORE_REQUEST'] = basename($path),
'Index' => $replacements['INDEX_REQUEST'] = basename($path),
'Update' => $replacements['UPDATE_REQUEST'] = basename($path),
};

$namespaces[] = ('use ' . implode('\\', explode('/', $path)) . ';');
$namespaces[] = ('use '.implode('\\', explode('/', $path)).';');

}

Expand All @@ -154,11 +154,11 @@ private function setResourceNamespaces(array &$replacements)
$namespaces = [];

foreach (['Resource', 'Collection'] as $suffix) {
$path = $this->getModuleName() . '/'
. $this->getDefaultNamespace('resource') . '/'
. $this->option('model') . $suffix;
$path = $this->getModuleName().'/'
.$this->getDefaultNamespace('resource').'/'
.$this->option('model').$suffix;

$namespaces[] = ('use ' . implode('\\', explode('/', $path)) . ';');
$namespaces[] = ('use '.implode('\\', explode('/', $path)).';');

}

Expand Down
40 changes: 20 additions & 20 deletions src/Commands/CrudMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ public function handle()

private function createRequest()
{
if (!config('api-crud.templates.request.generate', true)) {
if (! config('api-crud.templates.request.generate', true)) {
return;
}
foreach (['Index', 'Store', 'Update'] as $prefix) {

$resourcePath = $this->getResourceName() . 'Request';
$resourcePath = $this->getResourceName().'Request';

$dir = dirname($resourcePath);

$dir = ($dir == '.') ? '' : $dir . '/';
$dir = ($dir == '.') ? '' : $dir.'/';

$resource = basename($resourcePath);

$options = [
'name' => $dir . $prefix . $resource,
'name' => $dir.$prefix.$resource,
'module' => $this->getModuleName(),
];

Expand All @@ -105,29 +105,29 @@ private function getResourceName()

private function createResource()
{
if (!config('api-crud.templates.resource.generate', true)) {
if (! config('api-crud.templates.resource.generate', true)) {
return;
}
$this->call('laraflow:make-resource', [
'name' => $this->getResourceName() . 'Resource',
'name' => $this->getResourceName().'Resource',
'module' => $this->getModuleName(),
]);

$this->call('laraflow:make-resource', [
'name' => $this->getResourceName() . 'Collection',
'name' => $this->getResourceName().'Collection',
'module' => $this->getModuleName(),
'--collection' => true,
]);
}

private function createController()
{
if (!config('api-crud.templates.controller.generate', true)) {
if (! config('api-crud.templates.controller.generate', true)) {
return;
}

$this->call('laraflow:make-controller', [
'name' => $this->getResourceName() . 'Controller',
'name' => $this->getResourceName().'Controller',
'--model' => $this->getResourceName(),
'module' => $this->getModuleName(),
'--crud' => true,
Expand All @@ -140,13 +140,13 @@ private function createController()
private function createModel()
{

if (!config('api-crud.templates.model.generate', true)) {
if (! config('api-crud.templates.model.generate', true)) {
return;
}
$this->call('laraflow:make-model', [
'name' => $this->getResourceName(),
'module' => $this->getModuleName(),
'--migration' => config('api-crud.templates.migration.generate', true)
'--migration' => config('api-crud.templates.migration.generate', true),
]);
}

Expand All @@ -157,14 +157,14 @@ private function updateRouteFile()
{
$filePath = base_path(config('api-crud.route_path', 'routes/api.php'));

if (!file_exists($filePath)) {
if (! file_exists($filePath)) {
throw new InvalidArgumentException("Route file location doesn't exist");
}

$fileContent = file_get_contents($filePath);

if (!str_contains($fileContent, '//DO NOT REMOVE THIS LINE//')) {
throw new GeneratorException("Route file missing the CRUD Pointer comment.");
if (! str_contains($fileContent, '//DO NOT REMOVE THIS LINE//')) {
throw new GeneratorException('Route file missing the CRUD Pointer comment.');
}

$singleName = Str::kebab(basename($this->getResourceName()));
Expand All @@ -174,12 +174,12 @@ private function updateRouteFile()
$controller =
GeneratorPath::convertPathToNamespace(
'\\'
. $this->getModuleName()
. '\\'
. GenerateConfigReader::read('controller')->getNamespace()
. '\\'
. $this->getResourceName()
. 'Controller::class'
.$this->getModuleName()
.'\\'
.GenerateConfigReader::read('controller')->getNamespace()
.'\\'
.$this->getResourceName()
.'Controller::class'
);

$template = <<<HTML
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/MigrationMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ protected function getDestinationFilePath(): string
{
$config = GenerateConfigReader::read($this->type);

return $config->getPath().'/' .$this->getFileName();
return $config->getPath().'/'.$this->getFileName();
}

protected function getFileName()
{
return date('Y_m_d_His_\c\r\e\a\t\e_') . Str::snake($this->argument('name')) . "_table.php";
return date('Y_m_d_His_\c\r\e\a\t\e_').Str::snake($this->argument('name')).'_table.php';
}
}
1 change: 0 additions & 1 deletion src/Commands/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ protected function handleOptionalSeedOption()
}
}


/**
* Get the console command arguments.
*
Expand Down
10 changes: 5 additions & 5 deletions src/Providers/ApiCrudServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ApiCrudServiceProvider extends ServiceProvider
public function register(): void
{
$this->mergeConfigFrom(
__DIR__ . '/../../config/api-crud.php', 'api-crud'
__DIR__.'/../../config/api-crud.php', 'api-crud'
);

$this->app->register(MacroServiceProvider::class);
Expand All @@ -25,17 +25,17 @@ public function register(): void
public function boot(): void
{
$this->publishes([
__DIR__ . '/../../config/api-crud.php' => config_path('api-crud.php'),
__DIR__.'/../../config/api-crud.php' => config_path('api-crud.php'),
], 'api-crud-config');

$this->loadTranslationsFrom(__DIR__ . '/../../lang', 'api-crud');
$this->loadTranslationsFrom(__DIR__.'/../../lang', 'api-crud');

$this->publishes([
__DIR__ . '/../../lang' => $this->app->langPath('vendor/api-crud'),
__DIR__.'/../../lang' => $this->app->langPath('vendor/api-crud'),
], 'api-crud-lang');

$this->publishes([
__DIR__ . '/../../stubs' => base_path('stubs/api-crud'),
__DIR__.'/../../stubs' => base_path('stubs/api-crud'),
], 'api-crud-stubs');

$this->loadCommands();
Expand Down
49 changes: 24 additions & 25 deletions src/Providers/MacroServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Laraflow\ApiCrud\Providers;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Response as ResponseFacade;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -29,8 +28,8 @@ public function boot(): void
* return response with http 200 as deleted
* resource
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('deleted', function ($data, array $headers = []) {
Expand All @@ -41,8 +40,8 @@ public function boot(): void
* return response with http 200 as soft deleted
* resource restored
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('restored', function ($data, array $headers = []) {
Expand All @@ -53,8 +52,8 @@ public function boot(): void
* return response with http 201 resource
* created on server
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('created', function ($data, array $headers = []) {
Expand All @@ -65,8 +64,8 @@ public function boot(): void
* return response with http 200 update
* request accepted
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('updated', function ($data, array $headers = []) {
Expand All @@ -77,8 +76,8 @@ public function boot(): void
* return response with http 202 export
* request accepted
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('exported', function ($data, array $headers = []) {
Expand All @@ -89,8 +88,8 @@ public function boot(): void
* return response with http 400 if business
* logic exception
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('failed', function ($data, array $headers = []) {
Expand All @@ -100,8 +99,8 @@ public function boot(): void
/**
* return response with http 200 for all success status
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('success', function ($data, array $headers = []) {
Expand All @@ -112,8 +111,8 @@ public function boot(): void
* return response with http 401 if request
* token or ip banned
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('banned', function ($data, array $headers = []) {
Expand All @@ -124,8 +123,8 @@ public function boot(): void
* return response with http 403 if access forbidden
* to that request
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('forbidden', function ($data, array $headers = []) {
Expand All @@ -135,8 +134,8 @@ public function boot(): void
/**
* return response with http 404 not found
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('notfound', function ($data, array $headers = []) {
Expand All @@ -146,8 +145,8 @@ public function boot(): void
/**
* return response with http 423 attempt locked
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('locked', function ($data, array $headers = []) {
Expand All @@ -157,8 +156,8 @@ public function boot(): void
/**
* return response with http 429 too many requests code
*
* @param $data
* @param array $headers
* @param $data
* @param array $headers
* @return JsonResponse
*/
ResponseFacade::macro('overflow', function ($data, array $headers = []) {
Expand Down
Loading

0 comments on commit f4558cb

Please sign in to comment.