From c9c4b1d6199b4f34bc7a473483bb3cd65530776a Mon Sep 17 00:00:00 2001 From: JhumanJ Date: Tue, 12 Oct 2021 10:59:44 +0000 Subject: [PATCH] Fix styling --- src/Http/Controllers/Controller.php | 2 +- src/Http/Controllers/CustomCodeController.php | 2 +- src/Http/Controllers/DashboardController.php | 4 ++-- src/Http/Controllers/HomeController.php | 11 ++++++----- src/Http/Middleware/CustomCodeEnabled.php | 2 +- src/Http/Requests/Dashboard/StoreRequest.php | 2 +- src/Http/Requests/Dashboard/UpdateRequest.php | 6 +++--- src/Http/Requests/Widgets/DataRequest.php | 13 +++++++------ src/LaravelModelStatsServiceProvider.php | 1 + src/Models/Dashboard.php | 2 +- src/Services/Tinker.php | 8 ++++---- 11 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Http/Controllers/Controller.php b/src/Http/Controllers/Controller.php index af95461..18567ff 100644 --- a/src/Http/Controllers/Controller.php +++ b/src/Http/Controllers/Controller.php @@ -2,9 +2,9 @@ namespace Jhumanj\LaravelModelStats\Http\Controllers; -use Illuminate\Http\JsonResponse; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Validation\ValidatesRequests; +use Illuminate\Http\JsonResponse; use Illuminate\Routing\Controller as BaseController; class Controller extends BaseController diff --git a/src/Http/Controllers/CustomCodeController.php b/src/Http/Controllers/CustomCodeController.php index 7b73002..9764429 100644 --- a/src/Http/Controllers/CustomCodeController.php +++ b/src/Http/Controllers/CustomCodeController.php @@ -3,9 +3,9 @@ namespace Jhumanj\LaravelModelStats\Http\Controllers; use Carbon\Carbon; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Validation\Rule; -use Illuminate\Http\JsonResponse; use Jhumanj\LaravelModelStats\Http\Middleware\CustomCodeEnabled; use Jhumanj\LaravelModelStats\Services\Tinker; diff --git a/src/Http/Controllers/DashboardController.php b/src/Http/Controllers/DashboardController.php index ff1e6f9..dc9baa9 100644 --- a/src/Http/Controllers/DashboardController.php +++ b/src/Http/Controllers/DashboardController.php @@ -2,10 +2,10 @@ namespace Jhumanj\LaravelModelStats\Http\Controllers; -use Illuminate\Http\JsonResponse; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Http\JsonResponse; use Jhumanj\LaravelModelStats\Http\Requests\Dashboard\StoreRequest; use Jhumanj\LaravelModelStats\Http\Requests\Dashboard\UpdateRequest; use Jhumanj\LaravelModelStats\Models\Dashboard; diff --git a/src/Http/Controllers/HomeController.php b/src/Http/Controllers/HomeController.php index 3857732..714296b 100644 --- a/src/Http/Controllers/HomeController.php +++ b/src/Http/Controllers/HomeController.php @@ -2,15 +2,15 @@ namespace Jhumanj\LaravelModelStats\Http\Controllers; -use Schema; -use ReflectionClass; use Illuminate\Container\Container; -use Illuminate\Contracts\View\View; +use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; -use Illuminate\Contracts\Foundation\Application; +use ReflectionClass; +use Schema; class HomeController extends Controller { @@ -38,6 +38,7 @@ private function getModels(): Collection $models = collect(File::allFiles(app_path())) ->map(function ($item) { $path = $item->getRelativePathName(); + return sprintf( '\%s%s', Container::getInstance()->getNamespace(), @@ -57,7 +58,7 @@ private function getModels(): Collection }); - return $models->map(fn(string $class) => [ + return $models->map(fn (string $class) => [ 'class' => $class, 'fields' => $this->getClassFields($class), ])->sortByDesc('class')->values(); diff --git a/src/Http/Middleware/CustomCodeEnabled.php b/src/Http/Middleware/CustomCodeEnabled.php index a249275..b9cb646 100644 --- a/src/Http/Middleware/CustomCodeEnabled.php +++ b/src/Http/Middleware/CustomCodeEnabled.php @@ -15,7 +15,7 @@ class CustomCodeEnabled */ public function handle($request, $next) { - if (!config('model-stats.allow_custom_code')) { + if (! config('model-stats.allow_custom_code')) { return response([ 'message' => 'Custom code not enabled.', ], 403); diff --git a/src/Http/Requests/Dashboard/StoreRequest.php b/src/Http/Requests/Dashboard/StoreRequest.php index b2e23fa..7925bab 100644 --- a/src/Http/Requests/Dashboard/StoreRequest.php +++ b/src/Http/Requests/Dashboard/StoreRequest.php @@ -14,7 +14,7 @@ class StoreRequest extends FormRequest public function rules(): array { return [ - 'name' => 'required|string|max:60', + 'name' => 'required|string|max:60', 'description' => 'required', ]; } diff --git a/src/Http/Requests/Dashboard/UpdateRequest.php b/src/Http/Requests/Dashboard/UpdateRequest.php index 331698f..634f0b5 100644 --- a/src/Http/Requests/Dashboard/UpdateRequest.php +++ b/src/Http/Requests/Dashboard/UpdateRequest.php @@ -14,9 +14,9 @@ class UpdateRequest extends FormRequest public function rules(): array { return [ - 'name' => 'required|string|max:60', - 'description' => 'required', - 'body' => 'sometimes|required', + 'name' => 'required|string|max:60', + 'description' => 'required', + 'body' => 'sometimes|required', 'body.widgets' => 'sometimes|array', ]; } diff --git a/src/Http/Requests/Widgets/DataRequest.php b/src/Http/Requests/Widgets/DataRequest.php index d9eb983..142cae0 100644 --- a/src/Http/Requests/Widgets/DataRequest.php +++ b/src/Http/Requests/Widgets/DataRequest.php @@ -38,11 +38,11 @@ class DataRequest extends FormRequest public function rules(): array { return [ - 'model' => ['required', Rule::in($this->getModels())], - 'aggregate_type' => ['required', Rule::in(static::ALLOWED_AGGREGATES_TYPES)], - 'date_column' => 'required', - 'date_from' => 'required|date_format:Y-m-d|before:date_to', - 'date_to' => 'required|date_format:Y-m-d|after:date_from', + 'model' => ['required', Rule::in($this->getModels())], + 'aggregate_type' => ['required', Rule::in(static::ALLOWED_AGGREGATES_TYPES)], + 'date_column' => 'required', + 'date_from' => 'required|date_format:Y-m-d|before:date_to', + 'date_to' => 'required|date_format:Y-m-d|after:date_from', 'aggregate_column' => [Rule::requiredIf(in_array($this->aggregate_type, self::AGGREGATES_TYPES_WITH_AGGREGATE_COLUMN, true))], ]; } @@ -52,6 +52,7 @@ private function getModels(): Collection $models = collect(File::allFiles(app_path())) ->map(function ($item) { $path = $item->getRelativePathName(); + return sprintf('\%s%s', Container::getInstance() ->getNamespace(), strtr(substr($path, 0, strrpos($path, '.')), '/', '\\')); })->filter(function ($class) { @@ -60,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 b86b557..50fc484 100644 --- a/src/LaravelModelStatsServiceProvider.php +++ b/src/LaravelModelStatsServiceProvider.php @@ -14,6 +14,7 @@ public function boot(): LaravelModelStatsServiceProvider { $this->registerPublishing(); $this->registerCommands(); + return parent::boot(); } diff --git a/src/Models/Dashboard.php b/src/Models/Dashboard.php index 77fabfd..82c0ec5 100644 --- a/src/Models/Dashboard.php +++ b/src/Models/Dashboard.php @@ -2,9 +2,9 @@ namespace Jhumanj\LaravelModelStats\Models; -use Illuminate\Support\Facades\Config; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Config; use Jhumanj\LaravelModelStats\Database\Factories\DashboardFactory; class Dashboard extends Model diff --git a/src/Services/Tinker.php b/src/Services/Tinker.php index abfc21f..2b7bce7 100644 --- a/src/Services/Tinker.php +++ b/src/Services/Tinker.php @@ -3,15 +3,15 @@ namespace Jhumanj\LaravelModelStats\Services; -use Exception; use Carbon\Carbon; +use Exception; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\QueryException; use Illuminate\Foundation\Application; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; -use Illuminate\Database\QueryException; use Laravel\Tinker\ClassAliasAutoloader; use Psy\Configuration; use Psy\ExecutionLoopClosure; @@ -59,8 +59,8 @@ public function execute(string $phpCode): string if (($lastException instanceof QueryException) && Str::of($lastException->getMessage()) ->contains(self::FAKE_WRITE_HOST)) { - return "For safety reasons, you can only query data with ModelStats. Write operations are forbidden."; - } + return "For safety reasons, you can only query data with ModelStats. Write operations are forbidden."; + } } // Make sure we have a result var