diff --git a/config/model-stats.php b/config/model-stats.php index 501bdd6..31d9ebf 100644 --- a/config/model-stats.php +++ b/config/model-stats.php @@ -16,8 +16,8 @@ | */ - 'enabled' => env('MODEL_STATS_ENABLED', true), - 'allow_custom_code' => env('MODEL_STATS_CUSTOM_CODE', false), + 'enabled' => env('MODEL_STATS_ENABLED', true), + 'allow_custom_code' => env('MODEL_STATS_CUSTOM_CODE', false), /* |-------------------------------------------------------------------------- @@ -29,7 +29,7 @@ | the existing middleware. Or, you can simply stick with this list. | */ - 'middleware' => [ + 'middleware' => [ 'web', \Jhumanj\LaravelModelStats\Http\Middleware\Authorize::class, ], @@ -43,7 +43,7 @@ | this configures the table name based on your connection. | */ - 'table_name' => 'model_stats_dashboards', + 'table_name' => 'model_stats_dashboards', /* |-------------------------------------------------------------------------- @@ -54,7 +54,7 @@ | This can be used to ensure a read-only connection, by using a custom connection with a read-only user. | */ - 'query_database_connection' => env('MODEL_STATS_DB_CONNECTION', env('DB_CONNECTION')), + 'query_database_connection' => env('MODEL_STATS_DB_CONNECTION', env('DB_CONNECTION')), /* |-------------------------------------------------------------------------- @@ -65,6 +65,6 @@ | be starting the '/stats' prefix, and names will start with 'stats.'. | */ - 'routes_prefix' => 'stats', + 'routes_prefix' => 'stats', 'route_names_prefix' => 'stats.', ]; diff --git a/database/factories/DashboardFactory.php b/database/factories/DashboardFactory.php index bbfb803..a1ddcf5 100644 --- a/database/factories/DashboardFactory.php +++ b/database/factories/DashboardFactory.php @@ -2,8 +2,8 @@ namespace Jhumanj\LaravelModelStats\Database\Factories; -use Jhumanj\LaravelModelStats\Models\Dashboard; use Illuminate\Database\Eloquent\Factories\Factory; +use Jhumanj\LaravelModelStats\Models\Dashboard; class DashboardFactory extends Factory { @@ -12,9 +12,9 @@ class DashboardFactory extends Factory public function definition(): array { return [ - 'name' => $this->faker->name, + 'name' => $this->faker->name, 'description' => $this->faker->sentence, - 'body' => '{"widgets":[]}', + 'body' => '{"widgets":[]}', ]; } } diff --git a/database/migrations/create_model-stats_table.php b/database/migrations/create_model-stats_table.php index b3f0060..9c832b1 100644 --- a/database/migrations/create_model-stats_table.php +++ b/database/migrations/create_model-stats_table.php @@ -1,12 +1,12 @@ name('api.')->group(function () { Route::apiResource('dashboards', \Jhumanj\LaravelModelStats\Http\Controllers\DashboardController::class); - Route::post('widgets/data', - [\Jhumanj\LaravelModelStats\Http\Controllers\StatController::class, 'widgetData']); - Route::post('widgets/custom-code/data', - [\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'widgetData']); + Route::post( + 'widgets/data', + [\Jhumanj\LaravelModelStats\Http\Controllers\StatController::class, 'widgetData'] + ); + Route::post( + 'widgets/custom-code/data', + [\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'widgetData'] + ); - Route::post('widgets/custom-code/execute', - [\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'executeCustomCode']); + Route::post( + 'widgets/custom-code/execute', + [\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'executeCustomCode'] + ); }); Route::get('/{view?}', [\Jhumanj\LaravelModelStats\Http\Controllers\HomeController::class, 'home']) diff --git a/src/AuthorizesRequests.php b/src/AuthorizesRequests.php index 2cc3077..cab5216 100644 --- a/src/AuthorizesRequests.php +++ b/src/AuthorizesRequests.php @@ -9,31 +9,21 @@ trait AuthorizesRequests { /** * The callback that should be used to authenticate ModelStats users. - * - * @var \Closure */ public static Closure $authUsing; /** * Register the ModelStats authentication callback. - * - * @param \Closure $callback - * - * @return static */ public static function auth(Closure $callback): static { static::$authUsing = $callback; - return new static; + return new static(); } /** * Determine if the given request can access the ModelStats dashboard. - * - * @param \Illuminate\Http\Request $request - * - * @return bool */ public static function check(Request $request): bool { diff --git a/src/Console/InstallModelStatsPackage.php b/src/Console/InstallModelStatsPackage.php index e0c8633..29d876a 100644 --- a/src/Console/InstallModelStatsPackage.php +++ b/src/Console/InstallModelStatsPackage.php @@ -1,6 +1,5 @@ delete(); return $this->success([ - 'message' => 'Dashboard deleted', + 'message' => 'Dashboard deleted', ]); } } diff --git a/src/Http/Controllers/HomeController.php b/src/Http/Controllers/HomeController.php index f3b0dbf..451d698 100644 --- a/src/Http/Controllers/HomeController.php +++ b/src/Http/Controllers/HomeController.php @@ -50,13 +50,12 @@ private function getModels(): Collection if (class_exists($class)) { $reflection = new ReflectionClass($class); $valid = $reflection->isSubclassOf(Model::class) && - !$reflection->isAbstract(); + ! $reflection->isAbstract(); } return $valid; }); - return $models->map(fn (string $class) => [ 'class' => $class, 'fields' => $this->getClassFields($class), @@ -65,6 +64,6 @@ private function getModels(): Collection private function getClassFields(string $class) { - return Schema::getColumnListing((new $class)->getTable()); + return Schema::getColumnListing((new $class())->getTable()); } } diff --git a/src/Http/Middleware/Authorize.php b/src/Http/Middleware/Authorize.php index d9b70f9..ba3f6d7 100644 --- a/src/Http/Middleware/Authorize.php +++ b/src/Http/Middleware/Authorize.php @@ -9,9 +9,8 @@ class Authorize /** * Handle the incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * + * @param \Illuminate\Http\Request $request + * @param \Closure $next * @return \Illuminate\Http\Response */ public function handle($request, $next) diff --git a/src/Http/Middleware/CustomCodeEnabled.php b/src/Http/Middleware/CustomCodeEnabled.php index c83f98c..e7967c2 100644 --- a/src/Http/Middleware/CustomCodeEnabled.php +++ b/src/Http/Middleware/CustomCodeEnabled.php @@ -1,6 +1,5 @@ 'Custom code not enabled.', ], 403); diff --git a/src/Http/Requests/Dashboard/StoreRequest.php b/src/Http/Requests/Dashboard/StoreRequest.php index 7925bab..bfdfe94 100644 --- a/src/Http/Requests/Dashboard/StoreRequest.php +++ b/src/Http/Requests/Dashboard/StoreRequest.php @@ -8,8 +8,6 @@ class StoreRequest extends FormRequest { /** * Get the validation rules that apply to the request. - * - * @return array */ public function rules(): array { diff --git a/src/Http/Requests/Dashboard/UpdateRequest.php b/src/Http/Requests/Dashboard/UpdateRequest.php index 634f0b5..bccafdf 100644 --- a/src/Http/Requests/Dashboard/UpdateRequest.php +++ b/src/Http/Requests/Dashboard/UpdateRequest.php @@ -8,8 +8,6 @@ class UpdateRequest extends FormRequest { /** * Get the validation rules that apply to the request. - * - * @return array */ public function rules(): array { diff --git a/src/Http/Requests/Widgets/DataRequest.php b/src/Http/Requests/Widgets/DataRequest.php index ac34d28..a12735d 100644 --- a/src/Http/Requests/Widgets/DataRequest.php +++ b/src/Http/Requests/Widgets/DataRequest.php @@ -31,8 +31,6 @@ class DataRequest extends FormRequest /** * Get the validation rules that apply to the request. - * - * @return array */ public function rules(): array { @@ -63,7 +61,7 @@ private function getModels(): Collection if (class_exists($class)) { $reflection = new \ReflectionClass($class); $valid = $reflection->isSubclassOf(Model::class) - && !$reflection->isAbstract(); + && ! $reflection->isAbstract(); } return $valid; diff --git a/src/LaravelModelStatsServiceProvider.php b/src/LaravelModelStatsServiceProvider.php index 50fc484..93490ee 100644 --- a/src/LaravelModelStatsServiceProvider.php +++ b/src/LaravelModelStatsServiceProvider.php @@ -42,14 +42,12 @@ public function configurePackage(Package $package): void /** * Register the package's publishable resources. - * - * @return void */ private function registerPublishing(): void { if ($this->app->runningInConsole()) { $this->publishes([ - __DIR__ . '/../stubs/ModelStatsServiceProvider.stub' => app_path('Providers/ModelStatsServiceProvider.php'), + __DIR__.'/../stubs/ModelStatsServiceProvider.stub' => app_path('Providers/ModelStatsServiceProvider.php'), ], 'model-stats-provider'); $this->publishes([ @@ -60,8 +58,6 @@ private function registerPublishing(): void /** * Register the package's commands. - * - * @return void */ protected function registerCommands(): void { @@ -78,6 +74,6 @@ protected function registerCommands(): void */ protected function loadMigrations(): void { - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } } diff --git a/src/ModelStatsServiceProvider.php b/src/ModelStatsServiceProvider.php index ee18425..824f276 100644 --- a/src/ModelStatsServiceProvider.php +++ b/src/ModelStatsServiceProvider.php @@ -10,8 +10,6 @@ class ModelStatsServiceProvider extends ServiceProvider { /** * Bootstrap any application services. - * - * @return void */ public function boot(): void { @@ -20,8 +18,6 @@ public function boot(): void /** * Configure the ModelStats authorization services. - * - * @return void */ protected function authorization(): void { @@ -37,8 +33,6 @@ protected function authorization(): void * Register the ModelStats gate. * * This gate determines who can access ModelStats in non-local environments. - * - * @return void */ protected function gate(): void { diff --git a/src/Services/ModelStats.php b/src/Services/ModelStats.php index 13df832..a528adf 100644 --- a/src/Services/ModelStats.php +++ b/src/Services/ModelStats.php @@ -37,9 +37,9 @@ public function getDailyHistogram( } $data = $dataQuery->select([ - DB::raw('DATE(' . $dateFieldName . ') as date'), + DB::raw('DATE('.$dateFieldName.') as date'), DB::raw('COUNT(*) as "count"'), - ])->get()->pluck("count", "date"); + ])->get()->pluck('count', 'date'); $cumulatedSum = null; if ($cumulated) { @@ -80,7 +80,7 @@ public function getGroupByCount( string $dateFieldName, string $aggregateColumn ): array { - $tableName = (new $this->class)->getTable(); + $tableName = (new $this->class())->getTable(); $mapping = []; DB::table($tableName)->where($dateFieldName, '>=', $from->startOfDay()) @@ -106,11 +106,11 @@ public static function fillMissingDays($data, Carbon $since, Carbon $to, $defaul foreach (array_reverse(range(0, $daysSince)) as $number) { $dateKey = $to->copy()->subDays($number)->format('Y-m-d'); - if (!isset($data[$dateKey])) { + if (! isset($data[$dateKey])) { $data[$dateKey] = $defaultValue; } - if (!is_null($cumulatedSum)) { + if (! is_null($cumulatedSum)) { $data[$dateKey] += $cumulatedSum; $cumulatedSum = $data[$dateKey]; } diff --git a/src/Services/Tinker.php b/src/Services/Tinker.php index 4e565fa..eb2dbc9 100644 --- a/src/Services/Tinker.php +++ b/src/Services/Tinker.php @@ -1,6 +1,5 @@ getMessage()) - ->contains("SQLSTATE[42501]: Insufficient privilege")) { - return "For safety reasons, you can only query data with ModelStats. Write operations are forbidden."; + ->contains('SQLSTATE[42501]: Insufficient privilege')) { + return 'For safety reasons, you can only query data with ModelStats. Write operations are forbidden.'; } }