Skip to content

Commit

Permalink
Merge pull request #518 from nasirkhan/code-audit
Browse files Browse the repository at this point in the history
Code audit/ analysis and code fix
  • Loading branch information
nasirkhan authored Nov 24, 2023
2 parents 7bd1d30 + f550065 commit 5778fb9
Show file tree
Hide file tree
Showing 85 changed files with 4,147 additions and 2,163 deletions.
2 changes: 1 addition & 1 deletion Modules/Article/Console/UpdateCategoryNameInPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle()
}

// end note, show total updated rows in total
echo "\n\n Total $total_update_count posts updated.";
echo "\n\n Total {$total_update_count} posts updated.";

echo "\n\n";
}
Expand Down
1 change: 0 additions & 1 deletion Modules/Article/Database/Seeders/ArticleDatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Modules\Article\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Modules\Article\Models\Post;
Expand Down
38 changes: 19 additions & 19 deletions Modules/Article/Http/Controllers/Backend/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function index()
Log::info(label_case($module_title.' '.$module_action).' | User:'.Auth::user()->name.'(ID:'.Auth::user()->id.')');

return view(
"article::backend.$module_path.index_datatable",
compact('module_title', 'module_name', "$module_name", 'module_icon', 'module_name_singular', 'module_action')
"article::backend.{$module_path}.index_datatable",
compact('module_title', 'module_name', "{$module_name}", 'module_icon', 'module_name_singular', 'module_action')
);
}

Expand All @@ -97,7 +97,7 @@ public function index_data()
return view('backend.includes.action_column', compact('module_name', 'data'));
})
->editColumn('name', function ($data) {
$is_featured = ($data->is_featured) ? '<span class="badge bg-primary">Featured</span>' : '';
$is_featured = $data->is_featured ? '<span class="badge bg-primary">Featured</span>' : '';

return $data->name.' '.$data->status_formatted.' '.$is_featured;
})
Expand All @@ -108,9 +108,9 @@ public function index_data()

if ($diff < 25) {
return $data->updated_at->diffForHumans();
} else {
return $data->updated_at->isoFormat('LLLL');
}

return $data->updated_at->isoFormat('LLLL');
})
->rawColumns(['name', 'status', 'action'])
->orderColumns(['id'], '-:column $1')
Expand Down Expand Up @@ -139,7 +139,7 @@ public function index_list(Request $request)
return response()->json([]);
}

$query_data = $module_model::where('name', 'LIKE', "%$term%")->published()->limit(10)->get();
$query_data = $module_model::where('name', 'LIKE', "%{$term}%")->published()->limit(10)->get();

$$module_name = [];

Expand Down Expand Up @@ -174,7 +174,7 @@ public function create()
Log::info(label_case($module_title.' '.$module_action).' | User:'.Auth::user()->name.'(ID:'.Auth::user()->id.')');

return view(
"article::backend.$module_name.create",
"article::backend.{$module_name}.create",
compact('module_title', 'module_name', 'module_icon', 'module_action', 'module_name_singular', 'categories')
);
}
Expand Down Expand Up @@ -208,7 +208,7 @@ public function store(PostsRequest $request)

Log::info(label_case($module_title.' '.$module_action)." | '".$$module_name_singular->name.'(ID:'.$$module_name_singular->id.") ' by User:".Auth::user()->name.'(ID:'.Auth::user()->id.')');

return redirect("admin/$module_name");
return redirect("admin/{$module_name}");
}

/**
Expand Down Expand Up @@ -239,8 +239,8 @@ public function show($id)
Log::info(label_case($module_title.' '.$module_action).' | User:'.Auth::user()->name.'(ID:'.Auth::user()->id.')');

return view(
"article::backend.$module_name.show",
compact('module_title', 'module_name', 'module_icon', 'module_name_singular', 'module_action', "$module_name_singular", 'activities')
"article::backend.{$module_name}.show",
compact('module_title', 'module_name', 'module_icon', 'module_name_singular', 'module_action', "{$module_name_singular}", 'activities')
);
}

Expand Down Expand Up @@ -268,8 +268,8 @@ public function edit($id)
Log::info(label_case($module_title.' '.$module_action)." | '".$$module_name_singular->name.'(ID:'.$$module_name_singular->id.") ' by User:".Auth::user()->name.'(ID:'.Auth::user()->id.')');

return view(
"article::backend.$module_name.edit",
compact('categories', 'module_title', 'module_name', 'module_icon', 'module_name_singular', 'module_action', "$module_name_singular")
"article::backend.{$module_name}.edit",
compact('categories', 'module_title', 'module_name', 'module_icon', 'module_name_singular', 'module_action', "{$module_name_singular}")
);
}

Expand All @@ -295,7 +295,7 @@ public function update(PostsRequest $request, $id)

$$module_name_singular->update($request->except('tags_list'));

if ($request->input('tags_list') == null) {
if ($request->input('tags_list') === null) {
$tags_list = [];
} else {
$tags_list = $request->input('tags_list');
Expand All @@ -308,7 +308,7 @@ public function update(PostsRequest $request, $id)

Log::info(label_case($module_title.' '.$module_action)." | '".$$module_name_singular->name.'(ID:'.$$module_name_singular->id.") ' by User:".Auth::user()->name.'(ID:'.Auth::user()->id.')');

return redirect("admin/$module_name");
return redirect("admin/{$module_name}");
}

/**
Expand Down Expand Up @@ -336,7 +336,7 @@ public function destroy($id)

Log::info(label_case($module_title.' '.$module_action)." | '".$$module_name_singular->name.', ID:'.$$module_name_singular->id." ' by User:".Auth::user()->name.'(ID:'.Auth::user()->id.')');

return redirect("admin/$module_name");
return redirect("admin/{$module_name}");
}

/**
Expand All @@ -361,8 +361,8 @@ public function trashed()
Log::info(label_case($module_title.' '.$module_action).' | User:'.Auth::user()->name);

return view(
"article::backend.$module_name.trash",
compact('module_title', 'module_name', "$module_name", 'module_icon', 'module_name_singular', 'module_action')
"article::backend.{$module_name}.trash",
compact('module_title', 'module_name', "{$module_name}", 'module_icon', 'module_name_singular', 'module_action')
);
}

Expand All @@ -389,8 +389,8 @@ public function restore($id)

Flash::success('<i class="fas fa-check"></i> '.label_case($module_name_singular).' Data Restoreded Successfully!')->important();

Log::info(label_case($module_action)." '$module_name': '".$$module_name_singular->name.', ID:'.$$module_name_singular->id." ' by User:".Auth::user()->name.'(ID:'.Auth::user()->id.')');
Log::info(label_case($module_action)." '{$module_name}': '".$$module_name_singular->name.', ID:'.$$module_name_singular->id." ' by User:".Auth::user()->name.'(ID:'.Auth::user()->id.')');

return redirect("admin/$module_name");
return redirect("admin/{$module_name}");
}
}
8 changes: 4 additions & 4 deletions Modules/Article/Http/Controllers/Frontend/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function index()
$$module_name = $module_model::latest()->with(['category', 'tags', 'comments'])->paginate();

return view(
"article::frontend.$module_path.index",
compact('module_title', 'module_name', "$module_name", 'module_icon', 'module_action', 'module_name_singular')
"article::frontend.{$module_path}.index",
compact('module_title', 'module_name', "{$module_name}", 'module_icon', 'module_action', 'module_name_singular')
);
}

Expand Down Expand Up @@ -86,8 +86,8 @@ public function show($hashid)
event(new PostViewed($$module_name_singular));

return view(
"article::frontend.$module_name.show",
compact('module_title', 'module_name', 'module_icon', 'module_action', 'module_name_singular', "$module_name_singular", 'meta_page_type')
"article::frontend.{$module_name}.show",
compact('module_title', 'module_name', 'module_icon', 'module_action', 'module_name_singular', "{$module_name_singular}", 'meta_page_type')
);
}
}
1 change: 0 additions & 1 deletion Modules/Article/Listeners/PostCreated/CreatePostData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class CreatePostData implements ShouldQueue
*/
public function __construct()
{
//
}

/**
Expand Down
1 change: 0 additions & 1 deletion Modules/Article/Listeners/PostUpdated/UpdatePostData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class UpdatePostData implements ShouldQueue
*/
public function __construct()
{
//
}

/**
Expand Down
1 change: 0 additions & 1 deletion Modules/Article/Listeners/PostViewed/IncrementHitCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class IncrementHitCount implements ShouldQueue
*/
public function __construct()
{
//
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Modules/Article/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function setPublishedAtAttribute($value)
{
$this->attributes['published_at'] = $value;

if (empty($value) && $this->attributes['status'] == 1) {
if (empty($value) && $this->attributes['status'] === 1) {
$this->attributes['published_at'] = Carbon::now();
}
}
Expand Down
11 changes: 4 additions & 7 deletions Modules/Article/Models/Presenters/PostPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function getPublishedAtFormattedAttribute()

if ($diff < 24) {
return $this->published_at->diffForHumans();
} else {
return $this->published_at->isoFormat('llll');
}

return $this->published_at->isoFormat('llll');
}

public function getPublishedAtFormattedBengaliAttribute()
Expand All @@ -48,13 +48,10 @@ public function getPublishedAtFormattedBengaliAttribute()

if ($diff < 24) {
return $this->published_at->diffForHumans();
} else {
$date_string = $this->published_at->isoFormat('llll');
}
$date_string = $this->published_at->isoFormat('llll');

$return_string = en2bnDate($date_string);

return $return_string;
return en2bnDate($date_string);
}

public function getStatusFormattedAttribute()
Expand Down
52 changes: 26 additions & 26 deletions Modules/Article/Providers/ArticleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,6 @@ public function register()
$this->app->register(RouteServiceProvider::class);
}

/**
* Register config.
*
* @return void
*/
protected function registerConfig()
{
$this->publishes([
module_path('Article', 'Config/config.php') => config_path('article.php'),
], 'config');
$this->mergeConfigFrom(
module_path('Article', 'Config/config.php'),
'article'
);
}

/**
* Register views.
*
Expand Down Expand Up @@ -98,6 +82,32 @@ public function registerTranslations()
}
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [];
}

/**
* Register config.
*
* @return void
*/
protected function registerConfig()
{
$this->publishes([
module_path('Article', 'Config/config.php') => config_path('article.php'),
], 'config');
$this->mergeConfigFrom(
module_path('Article', 'Config/config.php'),
'article'
);
}

/**
* Register commands.
*
Expand All @@ -117,16 +127,6 @@ protected function registerCommands($namespace = '')
$this->commands($classes);
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [];
}

private function getPublishableViewPaths(): array
{
$paths = [];
Expand Down
2 changes: 0 additions & 2 deletions Modules/Article/Routes/api.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
Expand Down
17 changes: 10 additions & 7 deletions Modules/Article/Routes/web.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

use Illuminate\Support\Facades\Route;

/*
*
* Frontend Routes
*
* --------------------------------------------------------------------
*/

Route::group(['namespace' => '\Modules\Article\Http\Controllers\Frontend', 'as' => 'frontend.', 'middleware' => 'web', 'prefix' => ''], function () {
/*
*
Expand All @@ -15,8 +18,8 @@
*/
$module_name = 'posts';
$controller_name = 'PostsController';
Route::get("$module_name", ['as' => "$module_name.index", 'uses' => "$controller_name@index"]);
Route::get("$module_name/{id}/{slug?}", ['as' => "$module_name.show", 'uses' => "$controller_name@show"]);
Route::get("{$module_name}", ['as' => "{$module_name}.index", 'uses' => "{$controller_name}@index"]);
Route::get("{$module_name}/{id}/{slug?}", ['as' => "{$module_name}.show", 'uses' => "{$controller_name}@show"]);

// /*
// *
Expand Down Expand Up @@ -53,11 +56,11 @@
*/
$module_name = 'posts';
$controller_name = 'PostsController';
Route::get("$module_name/index_list", ['as' => "$module_name.index_list", 'uses' => "$controller_name@index_list"]);
Route::get("$module_name/index_data", ['as' => "$module_name.index_data", 'uses' => "$controller_name@index_data"]);
Route::get("$module_name/trashed", ['as' => "$module_name.trashed", 'uses' => "$controller_name@trashed"]);
Route::patch("$module_name/trashed/{id}", ['as' => "$module_name.restore", 'uses' => "$controller_name@restore"]);
Route::resource("$module_name", "$controller_name");
Route::get("{$module_name}/index_list", ['as' => "{$module_name}.index_list", 'uses' => "{$controller_name}@index_list"]);
Route::get("{$module_name}/index_data", ['as' => "{$module_name}.index_data", 'uses' => "{$controller_name}@index_data"]);
Route::get("{$module_name}/trashed", ['as' => "{$module_name}.trashed", 'uses' => "{$controller_name}@trashed"]);
Route::patch("{$module_name}/trashed/{id}", ['as' => "{$module_name}.restore", 'uses' => "{$controller_name}@restore"]);
Route::resource("{$module_name}", "{$controller_name}");

// /*
// *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function store(Request $request)

logUserAccess($module_title.' '.$module_action.' | Id: '.$$module_name_singular->id);

return redirect("admin/$module_name");
return redirect("admin/{$module_name}");
}

/**
Expand All @@ -89,8 +89,8 @@ public function show($id)
logUserAccess($module_title.' '.$module_action.' | Id: '.$$module_name_singular->id);

return view(
"$module_path.$module_name.show",
compact('module_title', 'module_name', 'module_path', 'module_icon', 'module_name_singular', 'module_action', "$module_name_singular", 'posts')
"{$module_path}.{$module_name}.show",
compact('module_title', 'module_name', 'module_path', 'module_icon', 'module_name_singular', 'module_action', "{$module_name_singular}", 'posts')
);
}

Expand Down Expand Up @@ -131,7 +131,7 @@ public function update(Request $request, $id)

$$module_name_singular->save();
}
if ($request->image_remove == 'image_remove') {
if ($request->image_remove === 'image_remove') {
if ($$module_name_singular->getMedia($module_name)->first()) {
$$module_name_singular->getMedia($module_name)->first()->delete();

Expand All @@ -145,6 +145,6 @@ public function update(Request $request, $id)

logUserAccess($module_title.' '.$module_action.' | Id: '.$$module_name_singular->id);

return redirect()->route("backend.$module_name.show", $$module_name_singular->id);
return redirect()->route("backend.{$module_name}.show", $$module_name_singular->id);
}
}
Loading

0 comments on commit 5778fb9

Please sign in to comment.