Skip to content

Commit 9164f6c

Browse files
committed
Run pint --preset=laravel
1 parent d8d36a3 commit 9164f6c

17 files changed

+43
-75
lines changed

config/model-stats.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
|
1717
*/
1818

19-
'enabled' => env('MODEL_STATS_ENABLED', true),
20-
'allow_custom_code' => env('MODEL_STATS_CUSTOM_CODE', false),
19+
'enabled' => env('MODEL_STATS_ENABLED', true),
20+
'allow_custom_code' => env('MODEL_STATS_CUSTOM_CODE', false),
2121

2222
/*
2323
|--------------------------------------------------------------------------
@@ -29,7 +29,7 @@
2929
| the existing middleware. Or, you can simply stick with this list.
3030
|
3131
*/
32-
'middleware' => [
32+
'middleware' => [
3333
'web',
3434
\Jhumanj\LaravelModelStats\Http\Middleware\Authorize::class,
3535
],
@@ -43,7 +43,7 @@
4343
| this configures the table name based on your connection.
4444
|
4545
*/
46-
'table_name' => 'model_stats_dashboards',
46+
'table_name' => 'model_stats_dashboards',
4747

4848
/*
4949
|--------------------------------------------------------------------------
@@ -54,7 +54,7 @@
5454
| This can be used to ensure a read-only connection, by using a custom connection with a read-only user.
5555
|
5656
*/
57-
'query_database_connection' => env('MODEL_STATS_DB_CONNECTION', env('DB_CONNECTION')),
57+
'query_database_connection' => env('MODEL_STATS_DB_CONNECTION', env('DB_CONNECTION')),
5858

5959
/*
6060
|--------------------------------------------------------------------------
@@ -65,6 +65,6 @@
6565
| be starting the '/stats' prefix, and names will start with 'stats.'.
6666
|
6767
*/
68-
'routes_prefix' => 'stats',
68+
'routes_prefix' => 'stats',
6969
'route_names_prefix' => 'stats.',
7070
];

database/factories/DashboardFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Jhumanj\LaravelModelStats\Database\Factories;
44

5-
use Jhumanj\LaravelModelStats\Models\Dashboard;
65
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Jhumanj\LaravelModelStats\Models\Dashboard;
77

88
class DashboardFactory extends Factory
99
{
@@ -12,9 +12,9 @@ class DashboardFactory extends Factory
1212
public function definition(): array
1313
{
1414
return [
15-
'name' => $this->faker->name,
15+
'name' => $this->faker->name,
1616
'description' => $this->faker->sentence,
17-
'body' => '{"widgets":[]}',
17+
'body' => '{"widgets":[]}',
1818
];
1919
}
2020
}

database/migrations/create_model-stats_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
use Illuminate\Support\Facades\Config;
43
use Illuminate\Database\Migrations\Migration;
54
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\Facades\Schema;
77

8-
return new class extends Migration {
9-
8+
return new class() extends Migration
9+
{
1010
public function up(): void
1111
{
1212
Schema::create(Config::get('model-stats.table_name'), function (Blueprint $table) {

routes/web.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88

99
Route::prefix('api')->name('api.')->group(function () {
1010
Route::apiResource('dashboards', \Jhumanj\LaravelModelStats\Http\Controllers\DashboardController::class);
11-
Route::post('widgets/data',
12-
[\Jhumanj\LaravelModelStats\Http\Controllers\StatController::class, 'widgetData']);
13-
Route::post('widgets/custom-code/data',
14-
[\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'widgetData']);
11+
Route::post(
12+
'widgets/data',
13+
[\Jhumanj\LaravelModelStats\Http\Controllers\StatController::class, 'widgetData']
14+
);
15+
Route::post(
16+
'widgets/custom-code/data',
17+
[\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'widgetData']
18+
);
1519

16-
Route::post('widgets/custom-code/execute',
17-
[\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'executeCustomCode']);
20+
Route::post(
21+
'widgets/custom-code/execute',
22+
[\Jhumanj\LaravelModelStats\Http\Controllers\CustomCodeController::class, 'executeCustomCode']
23+
);
1824
});
1925

2026
Route::get('/{view?}', [\Jhumanj\LaravelModelStats\Http\Controllers\HomeController::class, 'home'])

src/AuthorizesRequests.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,21 @@ trait AuthorizesRequests
99
{
1010
/**
1111
* The callback that should be used to authenticate ModelStats users.
12-
*
13-
* @var \Closure
1412
*/
1513
public static Closure $authUsing;
1614

1715
/**
1816
* Register the ModelStats authentication callback.
19-
*
20-
* @param \Closure $callback
21-
*
22-
* @return static
2317
*/
2418
public static function auth(Closure $callback): static
2519
{
2620
static::$authUsing = $callback;
2721

28-
return new static;
22+
return new static();
2923
}
3024

3125
/**
3226
* Determine if the given request can access the ModelStats dashboard.
33-
*
34-
* @param \Illuminate\Http\Request $request
35-
*
36-
* @return bool
3727
*/
3828
public static function check(Request $request): bool
3929
{

src/Console/InstallModelStatsPackage.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
namespace Jhumanj\LaravelModelStats\Console;
54

65
use Illuminate\Console\Command;
@@ -32,8 +31,6 @@ public function handle(): void
3231

3332
/**
3433
* Register the ModelStats service provider in the application configuration file.
35-
*
36-
* @return void
3734
*/
3835
private function registerModelStatsServiceProvider(): void
3936
{

src/Http/Controllers/DashboardController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function destroy(Dashboard $dashboard): JsonResponse
3939
$dashboard->delete();
4040

4141
return $this->success([
42-
'message' => 'Dashboard deleted',
42+
'message' => 'Dashboard deleted',
4343
]);
4444
}
4545
}

src/Http/Controllers/HomeController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ private function getModels(): Collection
5050
if (class_exists($class)) {
5151
$reflection = new ReflectionClass($class);
5252
$valid = $reflection->isSubclassOf(Model::class) &&
53-
!$reflection->isAbstract();
53+
! $reflection->isAbstract();
5454
}
5555

5656
return $valid;
5757
});
5858

59-
6059
return $models->map(fn (string $class) => [
6160
'class' => $class,
6261
'fields' => $this->getClassFields($class),
@@ -65,6 +64,6 @@ private function getModels(): Collection
6564

6665
private function getClassFields(string $class)
6766
{
68-
return Schema::getColumnListing((new $class)->getTable());
67+
return Schema::getColumnListing((new $class())->getTable());
6968
}
7069
}

src/Http/Middleware/Authorize.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ class Authorize
99
/**
1010
* Handle the incoming request.
1111
*
12-
* @param \Illuminate\Http\Request $request
13-
* @param \Closure $next
14-
*
12+
* @param \Illuminate\Http\Request $request
13+
* @param \Closure $next
1514
* @return \Illuminate\Http\Response
1615
*/
1716
public function handle($request, $next)

src/Http/Middleware/CustomCodeEnabled.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
<?php
22

3-
43
namespace Jhumanj\LaravelModelStats\Http\Middleware;
54

65
class CustomCodeEnabled
76
{
87
/**
98
* Handle the incoming request.
109
*
11-
* @param \Illuminate\Http\Request $request
12-
* @param \Closure $next
13-
*
10+
* @param \Illuminate\Http\Request $request
11+
* @param \Closure $next
1412
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
1513
*/
1614
public function handle($request, $next)
1715
{
18-
if (!config('model-stats.allow_custom_code')) {
16+
if (! config('model-stats.allow_custom_code')) {
1917
return response([
2018
'message' => 'Custom code not enabled.',
2119
], 403);

src/Http/Requests/Dashboard/StoreRequest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class StoreRequest extends FormRequest
88
{
99
/**
1010
* Get the validation rules that apply to the request.
11-
*
12-
* @return array
1311
*/
1412
public function rules(): array
1513
{

src/Http/Requests/Dashboard/UpdateRequest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class UpdateRequest extends FormRequest
88
{
99
/**
1010
* Get the validation rules that apply to the request.
11-
*
12-
* @return array
1311
*/
1412
public function rules(): array
1513
{

src/Http/Requests/Widgets/DataRequest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class DataRequest extends FormRequest
3131

3232
/**
3333
* Get the validation rules that apply to the request.
34-
*
35-
* @return array
3634
*/
3735
public function rules(): array
3836
{
@@ -63,7 +61,7 @@ private function getModels(): Collection
6361
if (class_exists($class)) {
6462
$reflection = new \ReflectionClass($class);
6563
$valid = $reflection->isSubclassOf(Model::class)
66-
&& !$reflection->isAbstract();
64+
&& ! $reflection->isAbstract();
6765
}
6866

6967
return $valid;

src/LaravelModelStatsServiceProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ public function configurePackage(Package $package): void
4242

4343
/**
4444
* Register the package's publishable resources.
45-
*
46-
* @return void
4745
*/
4846
private function registerPublishing(): void
4947
{
5048
if ($this->app->runningInConsole()) {
5149
$this->publishes([
52-
__DIR__ . '/../stubs/ModelStatsServiceProvider.stub' => app_path('Providers/ModelStatsServiceProvider.php'),
50+
__DIR__.'/../stubs/ModelStatsServiceProvider.stub' => app_path('Providers/ModelStatsServiceProvider.php'),
5351
], 'model-stats-provider');
5452

5553
$this->publishes([
@@ -60,8 +58,6 @@ private function registerPublishing(): void
6058

6159
/**
6260
* Register the package's commands.
63-
*
64-
* @return void
6561
*/
6662
protected function registerCommands(): void
6763
{
@@ -78,6 +74,6 @@ protected function registerCommands(): void
7874
*/
7975
protected function loadMigrations(): void
8076
{
81-
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
77+
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
8278
}
8379
}

src/ModelStatsServiceProvider.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class ModelStatsServiceProvider extends ServiceProvider
1010
{
1111
/**
1212
* Bootstrap any application services.
13-
*
14-
* @return void
1513
*/
1614
public function boot(): void
1715
{
@@ -20,8 +18,6 @@ public function boot(): void
2018

2119
/**
2220
* Configure the ModelStats authorization services.
23-
*
24-
* @return void
2521
*/
2622
protected function authorization(): void
2723
{
@@ -37,8 +33,6 @@ protected function authorization(): void
3733
* Register the ModelStats gate.
3834
*
3935
* This gate determines who can access ModelStats in non-local environments.
40-
*
41-
* @return void
4236
*/
4337
protected function gate(): void
4438
{

src/Services/ModelStats.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public function getDailyHistogram(
3737
}
3838

3939
$data = $dataQuery->select([
40-
DB::raw('DATE(' . $dateFieldName . ') as date'),
40+
DB::raw('DATE('.$dateFieldName.') as date'),
4141
DB::raw('COUNT(*) as "count"'),
42-
])->get()->pluck("count", "date");
42+
])->get()->pluck('count', 'date');
4343

4444
$cumulatedSum = null;
4545
if ($cumulated) {
@@ -80,7 +80,7 @@ public function getGroupByCount(
8080
string $dateFieldName,
8181
string $aggregateColumn
8282
): array {
83-
$tableName = (new $this->class)->getTable();
83+
$tableName = (new $this->class())->getTable();
8484

8585
$mapping = [];
8686
DB::table($tableName)->where($dateFieldName, '>=', $from->startOfDay())
@@ -106,11 +106,11 @@ public static function fillMissingDays($data, Carbon $since, Carbon $to, $defaul
106106

107107
foreach (array_reverse(range(0, $daysSince)) as $number) {
108108
$dateKey = $to->copy()->subDays($number)->format('Y-m-d');
109-
if (!isset($data[$dateKey])) {
109+
if (! isset($data[$dateKey])) {
110110
$data[$dateKey] = $defaultValue;
111111
}
112112

113-
if (!is_null($cumulatedSum)) {
113+
if (! is_null($cumulatedSum)) {
114114
$data[$dateKey] += $cumulatedSum;
115115
$cumulatedSum = $data[$dateKey];
116116
}

src/Services/Tinker.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
namespace Jhumanj\LaravelModelStats\Services;
54

65
use Carbon\Carbon;
@@ -21,15 +20,11 @@
2120
* Taken from https://github.com/spatie/laravel-web-tinker/blob/master/src/Tinker.php
2221
*
2322
* Class Tinker
24-
* @package Jhumanj\LaravelModelStats\Services
2523
*/
2624
class Tinker
2725
{
28-
29-
/** @var \Symfony\Component\Console\Output\BufferedOutput */
3026
protected BufferedOutput $output;
3127

32-
/** @var \Psy\Shell */
3328
protected Shell $shell;
3429

3530
public function __construct()
@@ -56,8 +51,8 @@ public function execute(string $phpCode): string
5651
$lastException = $resultVars['_e'];
5752
if (($lastException instanceof QueryException)
5853
&& Str::of($lastException->getMessage())
59-
->contains("SQLSTATE[42501]: Insufficient privilege")) {
60-
return "For safety reasons, you can only query data with ModelStats. Write operations are forbidden.";
54+
->contains('SQLSTATE[42501]: Insufficient privilege')) {
55+
return 'For safety reasons, you can only query data with ModelStats. Write operations are forbidden.';
6156
}
6257
}
6358

0 commit comments

Comments
 (0)