From 78e833fd68cc8e141fc09253cafa4a08b55342dc Mon Sep 17 00:00:00 2001 From: "quentin.schmick" Date: Fri, 11 Feb 2022 15:16:53 -0500 Subject: [PATCH 1/8] Updated to allow Laravel 9 usage; Updated CI to do a matrix of versions --- .github/workflows/laravel.yml | 26 +++++++++++++++++++++++--- .gitignore | 1 + composer.json | 2 +- docker-compose.yml | 2 +- docker/Dockerfile | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 9823892b..f157d659 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -4,9 +4,27 @@ on: [push, pull_request] jobs: laravel-tests: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ ubuntu-latest ] + php: [ 8.0, 8.1 ] + laravel: [ 9.* ] + stability: [ prefer-stable ] + include: + - laravel: 9.* + testbench: ^7.0 + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + steps: - uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none - name: Cache dependencies uses: actions/cache@v2 with: @@ -14,7 +32,9 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: | ${{ runner.os }}-composer- - - name: Install Dependencies - run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Execute tests (Unit and Feature tests) via PHPUnit run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index f169040a..5b112725 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ _ide_helper.php .DS_Store .idea *.sketch +.phpunit.result.cache diff --git a/composer.json b/composer.json index 602ba577..3d08110d 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.3", + "php": "^8.0.0|^8.1.0", "ext-json": "*", "doctrine/dbal": "^3.1", "illuminate/bus": "^8.11", diff --git a/docker-compose.yml b/docker-compose.yml index 49be20af..e3a25cb5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: - totem db: - image: mysql:8.0.20 + image: mysql/mysql-server:8.0.27 container_name: totem-db restart: unless-stopped environment: diff --git a/docker/Dockerfile b/docker/Dockerfile index e13022e3..3c63c8c0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.3.29-fpm +FROM arm64v8/php:8.1.0-fpm # Install system dependencies RUN apt-get update && apt-get install -y \ From 4a2913483f89db7984b4bbf32eafad5933f6109f Mon Sep 17 00:00:00 2001 From: "quentin.schmick" Date: Fri, 11 Feb 2022 15:48:29 -0500 Subject: [PATCH 2/8] Updated typing --- ...3421_update_task_results_duration_type.php | 2 +- src/Console/Commands/ListSchedule.php | 2 +- src/Contracts/TaskInterface.php | 43 +++++++++++-------- src/Events/BroadcastingEvent.php | 6 +-- src/Events/Creating.php | 7 ++- src/Events/Deleted.php | 2 - src/Events/Executed.php | 3 +- src/Events/TaskEvent.php | 2 +- src/Events/Updating.php | 7 ++- src/Frequency.php | 5 ++- .../Controllers/ActiveTasksController.php | 13 +++--- src/Http/Controllers/DashboardController.php | 6 ++- .../Controllers/ExecuteTasksController.php | 4 +- .../Controllers/ExportTasksController.php | 7 +-- .../Controllers/ImportTasksController.php | 7 +-- src/Http/Controllers/TasksController.php | 37 ++++++++-------- src/Http/Middleware/Authenticate.php | 11 +++-- src/Listeners/BuildCache.php | 2 +- src/Listeners/BustCache.php | 2 +- src/Listeners/BustCacheImmediately.php | 4 +- src/Listeners/Listener.php | 4 +- src/Notifications/TaskCompleted.php | 10 ++--- src/Parameter.php | 4 +- src/Repositories/EloquentTaskRepository.php | 8 ++-- src/Result.php | 14 +++--- src/Task.php | 29 +++++++------ src/Totem.php | 18 ++++---- src/TotemModel.php | 4 +- src/Traits/FrontendSortable.php | 4 +- src/Traits/HasFrequencies.php | 27 ++++++------ src/Traits/HasParameters.php | 13 ++++-- src/User.php | 4 +- 32 files changed, 171 insertions(+), 140 deletions(-) diff --git a/database/migrations/2019_09_25_103421_update_task_results_duration_type.php b/database/migrations/2019_09_25_103421_update_task_results_duration_type.php index eb07d72e..0c91404a 100644 --- a/database/migrations/2019_09_25_103421_update_task_results_duration_type.php +++ b/database/migrations/2019_09_25_103421_update_task_results_duration_type.php @@ -28,7 +28,7 @@ public function down() } /** - * @param bool $toFloat + * @param bool $toFloat */ private function migrateDurationValues(bool $toFloat = true) { diff --git a/src/Console/Commands/ListSchedule.php b/src/Console/Commands/ListSchedule.php index 0be8fafb..2fda418f 100644 --- a/src/Console/Commands/ListSchedule.php +++ b/src/Console/Commands/ListSchedule.php @@ -32,7 +32,7 @@ class ListSchedule extends Command /** * Create a new command instance. * - * @param Schedule $schedule + * @param Schedule $schedule * @return void */ public function __construct(Schedule $schedule) diff --git a/src/Contracts/TaskInterface.php b/src/Contracts/TaskInterface.php index d2b8efb7..a9e9313f 100644 --- a/src/Contracts/TaskInterface.php +++ b/src/Contracts/TaskInterface.php @@ -2,65 +2,70 @@ namespace Studio\Totem\Contracts; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Studio\Totem\Task; + interface TaskInterface { /** * Returns Eloquent Builder. * - * @return \Illuminate\Database\Eloquent\Builder + * @return Builder */ - public function builder(); + public function builder(): Builder; /** * Returns a task by its primary key. * - * @param int|\Studio\Totem\Task $id - * @return \Studio\Totem\Task + * @param int|Task $id + * @return Task */ - public function find($id); + public function find(Task|int $id): Task; /** * Returns all tasks. - * @return \Illuminate\Database\Eloquent\Collection + * @return Collection */ - public function findAll(); + public function findAll(): Collection; /** * Returns all active tasks. - * @return \Illuminate\Database\Eloquent\Collection + * + * @return Collection */ - public function findAllActive(); + public function findAllActive(): Collection; /** * Creates a new task with the given data. * - * @param array $input - * @return \Studio\Totem\Task + * @param array $input + * @return Task */ public function store(array $input); /** * Updates the given task with the given data. * - * @param array $input - * @param \Studio\Totem\Task $task - * @return \Studio\Totem\Task + * @param array $input + * @param Task $task + * @return Task */ - public function update(array $input, $task); + public function update(array $input, Task $task): Task; /** * Deletes the given task. * - * @param int|\Studio\Totem\Task $id + * @param int|Task $id * @return bool */ - public function destroy($id); + public function destroy(Task|int $id): bool; /** * Executes the given task. * - * @param int|\Studio\Totem\Task $id + * @param int|Task $id * @return bool */ - public function execute($id); + public function execute(Task|int $id): bool; } diff --git a/src/Events/BroadcastingEvent.php b/src/Events/BroadcastingEvent.php index bd4c9d2a..226d7aa3 100644 --- a/src/Events/BroadcastingEvent.php +++ b/src/Events/BroadcastingEvent.php @@ -13,9 +13,9 @@ class BroadcastingEvent extends TaskEvent implements ShouldBroadcast /** * Get the channels the event should broadcast on. * - * @return \Illuminate\Broadcasting\Channel|\Illuminate\Broadcasting\Channel[]|PrivateChannel + * @return PrivateChannel */ - public function broadcastOn() + public function broadcastOn(): PrivateChannel { return new PrivateChannel(config('totem.broadcasting.channel')); } @@ -25,7 +25,7 @@ public function broadcastOn() * * @return bool */ - public function broadcastWhen() + public function broadcastWhen(): bool { return config('totem.broadcasting.enabled'); } diff --git a/src/Events/Creating.php b/src/Events/Creating.php index b179055d..07e42ec4 100644 --- a/src/Events/Creating.php +++ b/src/Events/Creating.php @@ -2,7 +2,6 @@ namespace Studio\Totem\Events; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; @@ -16,7 +15,7 @@ class Creating implements ShouldBroadcast /** * @var array */ - private $input; + private array $input; /** * Create a new event instance. @@ -31,9 +30,9 @@ public function __construct(array $input) /** * Get the channels the event should broadcast on. * - * @return Channel|array + * @return PrivateChannel */ - public function broadcastOn() + public function broadcastOn(): PrivateChannel { return new PrivateChannel('channel-name'); } diff --git a/src/Events/Deleted.php b/src/Events/Deleted.php index 0b3d590a..572455e8 100644 --- a/src/Events/Deleted.php +++ b/src/Events/Deleted.php @@ -7,8 +7,6 @@ class Deleted extends Event /** * Create a new event instance. * - * @param array $input - * @param Task $task */ public function __construct() { diff --git a/src/Events/Executed.php b/src/Events/Executed.php index 666b7c2a..935b9b53 100644 --- a/src/Events/Executed.php +++ b/src/Events/Executed.php @@ -11,7 +11,8 @@ class Executed extends BroadcastingEvent * Executed constructor. * * @param Task $task - * @param string $started + * @param string|float|int $started + * @param $output */ public function __construct(Task $task, $started, $output) { diff --git a/src/Events/TaskEvent.php b/src/Events/TaskEvent.php index c64c85af..cb99e15e 100644 --- a/src/Events/TaskEvent.php +++ b/src/Events/TaskEvent.php @@ -13,7 +13,7 @@ class TaskEvent extends Event /** * @var Task */ - public $task; + public Task $task; /** * Constructor. diff --git a/src/Events/Updating.php b/src/Events/Updating.php index 95ff3b8c..41fecf2d 100644 --- a/src/Events/Updating.php +++ b/src/Events/Updating.php @@ -2,7 +2,6 @@ namespace Studio\Totem\Events; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\PrivateChannel; use Studio\Totem\Task; @@ -11,7 +10,7 @@ class Updating extends BroadcastingEvent /** * @var array */ - private $input; + private array $input; /** * Create a new event instance. @@ -28,9 +27,9 @@ public function __construct(array $input, Task $task) /** * Get the channels the event should broadcast on. * - * @return Channel|array + * @return PrivateChannel */ - public function broadcastOn() + public function broadcastOn(): PrivateChannel { return new PrivateChannel('channel-name'); } diff --git a/src/Frequency.php b/src/Frequency.php index 39755df3..f85eccc0 100644 --- a/src/Frequency.php +++ b/src/Frequency.php @@ -2,6 +2,7 @@ namespace Studio\Totem; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Studio\Totem\Traits\HasParameters; class Frequency extends TotemModel @@ -17,9 +18,9 @@ class Frequency extends TotemModel ]; /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function task() + public function task(): BelongsTo { return $this->belongsTo(Task::class); } diff --git a/src/Http/Controllers/ActiveTasksController.php b/src/Http/Controllers/ActiveTasksController.php index 2e93c1eb..596480fa 100644 --- a/src/Http/Controllers/ActiveTasksController.php +++ b/src/Http/Controllers/ActiveTasksController.php @@ -2,6 +2,7 @@ namespace Studio\Totem\Http\Controllers; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Studio\Totem\Contracts\TaskInterface; @@ -10,7 +11,7 @@ class ActiveTasksController extends Controller /** * @var TaskInterface */ - private $tasks; + private TaskInterface $tasks; /** * @param TaskInterface $tasks @@ -25,10 +26,10 @@ public function __construct(TaskInterface $tasks) /** * Store a newly active task in storage. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @param Request $request + * @return JsonResponse */ - public function store(Request $request) + public function store(Request $request): JsonResponse { $task = $this->tasks->activate($request->all()); @@ -39,9 +40,9 @@ public function store(Request $request) * Remove the specified resource from storage. * * @param int $id - * @return \Illuminate\Http\Response + * @return JsonResponse */ - public function destroy($id) + public function destroy(int $id): JsonResponse { $task = $this->tasks->deactivate($id); diff --git a/src/Http/Controllers/DashboardController.php b/src/Http/Controllers/DashboardController.php index 435bfe42..9f05db89 100644 --- a/src/Http/Controllers/DashboardController.php +++ b/src/Http/Controllers/DashboardController.php @@ -2,14 +2,16 @@ namespace Studio\Totem\Http\Controllers; +use Illuminate\Http\RedirectResponse; + class DashboardController extends Controller { /** * Single page application catch-all route. * - * @return \Illuminate\Http\Response + * @return RedirectResponse */ - public function index() + public function index(): RedirectResponse { return redirect()->route('totem.tasks.all'); } diff --git a/src/Http/Controllers/ExecuteTasksController.php b/src/Http/Controllers/ExecuteTasksController.php index 291d1e99..5a52fb64 100644 --- a/src/Http/Controllers/ExecuteTasksController.php +++ b/src/Http/Controllers/ExecuteTasksController.php @@ -10,13 +10,15 @@ class ExecuteTasksController extends Controller /** * @var TaskInterface */ - private $tasks; + private TaskInterface $tasks; /** * @param TaskInterface $tasks */ public function __construct(TaskInterface $tasks) { + parent::__construct(); + $this->tasks = $tasks; } diff --git a/src/Http/Controllers/ExportTasksController.php b/src/Http/Controllers/ExportTasksController.php index 3d4373dd..25ed463b 100644 --- a/src/Http/Controllers/ExportTasksController.php +++ b/src/Http/Controllers/ExportTasksController.php @@ -3,13 +3,14 @@ namespace Studio\Totem\Http\Controllers; use Studio\Totem\Contracts\TaskInterface; +use Symfony\Component\HttpFoundation\StreamedResponse; class ExportTasksController extends Controller { /** * @var TaskInterface */ - private $tasks; + private TaskInterface $tasks; /** * ExportTasksController constructor. @@ -25,9 +26,9 @@ public function __construct(TaskInterface $tasks) /** * Export all tasks to a json file. * - * @return \Symfony\Component\HttpFoundation\StreamedResponse + * @return StreamedResponse */ - public function index() + public function index() : StreamedResponse { $headers = [ 'Content-Type' => 'text/json', diff --git a/src/Http/Controllers/ImportTasksController.php b/src/Http/Controllers/ImportTasksController.php index f6e44d3e..5a2f4b5b 100644 --- a/src/Http/Controllers/ImportTasksController.php +++ b/src/Http/Controllers/ImportTasksController.php @@ -2,6 +2,7 @@ namespace Studio\Totem\Http\Controllers; +use Illuminate\Contracts\Filesystem\FileNotFoundException; use Studio\Totem\Contracts\TaskInterface; use Studio\Totem\Http\Requests\ImportRequest; @@ -10,7 +11,7 @@ class ImportTasksController extends Controller /** * @var TaskInterface */ - private $tasks; + private TaskInterface $tasks; /** * ImportTasksController constructor. @@ -25,8 +26,8 @@ public function __construct(TaskInterface $tasks) /** * Import tasks from a json file. - * @param \Studio\Totem\Http\Requests\ImportRequest $request - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException + * @param ImportRequest $request + * @throws FileNotFoundException */ public function index(ImportRequest $request) { diff --git a/src/Http/Controllers/TasksController.php b/src/Http/Controllers/TasksController.php index 6e3e48f4..ea5699f0 100644 --- a/src/Http/Controllers/TasksController.php +++ b/src/Http/Controllers/TasksController.php @@ -2,7 +2,10 @@ namespace Studio\Totem\Http\Controllers; +use Illuminate\Contracts\View\Factory; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Http\RedirectResponse; +use Illuminate\View\View; use Studio\Totem\Contracts\TaskInterface; use Studio\Totem\Http\Requests\TaskRequest; use Studio\Totem\Task; @@ -13,7 +16,7 @@ class TasksController extends Controller /** * @var TaskInterface */ - private $tasks; + private TaskInterface $tasks; /** * TasksController constructor. @@ -30,9 +33,9 @@ public function __construct(TaskInterface $tasks) /** * Display a listing of the tasks. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return View */ - public function index() + public function index() : View { return view('totem::tasks.index', [ 'tasks' => $this->tasks @@ -52,9 +55,9 @@ public function index() /** * Show the form for creating a new task. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return View */ - public function create() + public function create(): View { $commands = Totem::getCommands()->map(function ($command) { return ['name' => $command->getName(), 'description' => $command->getDescription()]; @@ -72,9 +75,9 @@ public function create() * Store a newly created task in storage. * * @param TaskRequest $request - * @return \Illuminate\Http\RedirectResponse + * @return RedirectResponse */ - public function store(TaskRequest $request) + public function store(TaskRequest $request): RedirectResponse { $this->tasks->store($request->all()); @@ -86,8 +89,8 @@ public function store(TaskRequest $request) /** * Display the specified task. * - * @param $task - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @param Task $task + * @return Factory|View */ public function view(Task $task) { @@ -99,10 +102,10 @@ public function view(Task $task) /** * Show the form for editing the specified task. * - * @param $task - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @param Task $task + * @return View */ - public function edit(Task $task) + public function edit(Task $task): View { $commands = Totem::getCommands()->map(function ($command) { return ['name' => $command->getName(), 'description' => $command->getDescription()]; @@ -120,10 +123,10 @@ public function edit(Task $task) * Update the specified task in storage. * * @param TaskRequest $request - * @param $task - * @return \Illuminate\Http\RedirectResponse + * @param Task $task + * @return RedirectResponse */ - public function update(TaskRequest $request, Task $task) + public function update(TaskRequest $request, Task $task): RedirectResponse { $task = $this->tasks->update($request->all(), $task); @@ -135,8 +138,8 @@ public function update(TaskRequest $request, Task $task) /** * Remove the specified task from storage. * - * @param $task - * @return \Illuminate\Http\RedirectResponse + * @param Task $task + * @return RedirectResponse */ public function destroy(Task $task) { diff --git a/src/Http/Middleware/Authenticate.php b/src/Http/Middleware/Authenticate.php index 945221dc..55ed6ce3 100644 --- a/src/Http/Middleware/Authenticate.php +++ b/src/Http/Middleware/Authenticate.php @@ -2,6 +2,9 @@ namespace Studio\Totem\Http\Middleware; +use Closure; +use Illuminate\Http\Request; +use Illuminate\Http\Response; use Studio\Totem\Totem; class Authenticate @@ -9,11 +12,11 @@ class Authenticate /** * Handle the incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return \Illuminate\Http\Response + * @param Request $request + * @param Closure $next + * @return Response */ - public function handle($request, $next) + public function handle(Request $request, Closure $next): Response { return Totem::check($request) ? $next($request) : abort(403); } diff --git a/src/Listeners/BuildCache.php b/src/Listeners/BuildCache.php index c34c5368..e1a0084d 100644 --- a/src/Listeners/BuildCache.php +++ b/src/Listeners/BuildCache.php @@ -9,7 +9,7 @@ class BuildCache extends Listener /** * Handle the event. * - * @param \Studio\Totem\Events\Event $event + * @param Event $event */ public function handle(Event $event) { diff --git a/src/Listeners/BustCache.php b/src/Listeners/BustCache.php index 12afda2d..4ad769eb 100644 --- a/src/Listeners/BustCache.php +++ b/src/Listeners/BustCache.php @@ -9,7 +9,7 @@ class BustCache extends Listener /** * Handle the event. * - * @param \Studio\Totem\Events\Event $event + * @param Event $event */ public function handle(Event $event) { diff --git a/src/Listeners/BustCacheImmediately.php b/src/Listeners/BustCacheImmediately.php index 5f3f17b9..e13c9257 100644 --- a/src/Listeners/BustCacheImmediately.php +++ b/src/Listeners/BustCacheImmediately.php @@ -10,7 +10,7 @@ class BustCacheImmediately /** * @var Container */ - protected $app; + protected Container $app; /** * Create the event listener. @@ -25,7 +25,7 @@ public function __construct(Container $app) /** * Handle the event. * - * @param \Studio\Totem\Events\Event $event + * @param Event $event */ public function handle(Event $event) { diff --git a/src/Listeners/Listener.php b/src/Listeners/Listener.php index db3fce85..8a07f557 100644 --- a/src/Listeners/Listener.php +++ b/src/Listeners/Listener.php @@ -11,12 +11,12 @@ class Listener implements ShouldQueue /** * @var TaskInterface. */ - protected $tasks; + protected TaskInterface $tasks; /** * @var Container */ - protected $app; + protected Container $app; /** * Create the event listener. diff --git a/src/Notifications/TaskCompleted.php b/src/Notifications/TaskCompleted.php index 84e2782a..1c244548 100644 --- a/src/Notifications/TaskCompleted.php +++ b/src/Notifications/TaskCompleted.php @@ -33,7 +33,7 @@ public function __construct($output) * @param mixed $notifiable * @return array */ - public function via($notifiable) + public function via(mixed $notifiable): array { $channels = []; if ($notifiable->notification_email_address) { @@ -53,9 +53,9 @@ public function via($notifiable) * Get the mail representation of the notification. * * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ - public function toMail($notifiable) + public function toMail(mixed $notifiable): MailMessage { return (new MailMessage) ->subject($notifiable->description) @@ -70,7 +70,7 @@ public function toMail($notifiable) * @param mixed $notifiable * @return NexmoMessage */ - public function toNexmo($notifiable) + public function toNexmo(mixed $notifiable): NexmoMessage { return (new NexmoMessage) ->content($notifiable->description.' just finished running.'); @@ -82,7 +82,7 @@ public function toNexmo($notifiable) * @param mixed $notifiable * @return SlackMessage */ - public function toSlack($notifiable) + public function toSlack(mixed $notifiable): SlackMessage { return (new SlackMessage) ->content(config('app.name')) diff --git a/src/Parameter.php b/src/Parameter.php index 87b30392..03d6511a 100644 --- a/src/Parameter.php +++ b/src/Parameter.php @@ -2,6 +2,8 @@ namespace Studio\Totem; +use Illuminate\Database\Eloquent\Relations\BelongsTo; + class Parameter extends TotemModel { protected $table = 'frequency_parameters'; @@ -12,7 +14,7 @@ class Parameter extends TotemModel 'value', ]; - public function task() + public function task(): BelongsTo { return $this->belongsTo(Frequency::class); } diff --git a/src/Repositories/EloquentTaskRepository.php b/src/Repositories/EloquentTaskRepository.php index 3fe9e899..6a7635b9 100644 --- a/src/Repositories/EloquentTaskRepository.php +++ b/src/Repositories/EloquentTaskRepository.php @@ -47,7 +47,7 @@ public function builder(): Builder * @param int|Task $id * @return int|Task */ - public function find($id) + public function find(Task|int $id) { if ($id instanceof Task) { return $id; @@ -133,7 +133,7 @@ public function update(array $input, $task) * @param int|Task $id * @return bool */ - public function destroy($id) + public function destroy(Task|int $id) { $task = $this->find($id); @@ -185,10 +185,10 @@ public function deactivate($id) /** * Execute a given task. * - * @param $id + * @param int|Task $id * @return int|Task */ - public function execute($id) + public function execute(Task|int $id) { $task = $this->find($id); $start = microtime(true); diff --git a/src/Result.php b/src/Result.php index a163dbb4..fead8de4 100644 --- a/src/Result.php +++ b/src/Result.php @@ -3,7 +3,9 @@ namespace Studio\Totem; use Database\Factories\TotemResultFactory; +use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\DB; @@ -18,11 +20,11 @@ class Result extends TotemModel 'result', ]; - protected $dates = [ - 'ran_at', + protected $casts = [ + 'ran_at' => 'datetime', ]; - public function task() + public function task(): BelongsTo { return $this->belongsTo(Task::class); } @@ -50,11 +52,9 @@ public function getAverageRunTime(): Builder } /** - * Create a new factory instance for the model. - * - * @return \Illuminate\Database\Eloquent\Factories\Factory + * @return TotemResultFactory */ - protected static function newFactory() + protected static function newFactory(): TotemResultFactory { return TotemResultFactory::new(); } diff --git a/src/Task.php b/src/Task.php index 19b9bb93..387e94d3 100644 --- a/src/Task.php +++ b/src/Task.php @@ -5,7 +5,9 @@ use Carbon\Carbon; use Cron\CronExpression; use Database\Factories\TotemTaskFactory; +use Exception; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Str; use Studio\Totem\Traits\FrontendSortable; @@ -56,7 +58,7 @@ class Task extends TotemModel * * @return bool */ - public function getActivatedAttribute() + public function getActivatedAttribute(): bool { return $this->is_active; } @@ -65,8 +67,9 @@ public function getActivatedAttribute() * Upcoming Accessor. * * @return string + * @throws Exception */ - public function getUpcomingAttribute() + public function getUpcomingAttribute(): string { return CronExpression::factory($this->getCronExpression())->getNextRunDate()->format('Y-m-d H:i:s'); } @@ -78,7 +81,7 @@ public function getUpcomingAttribute() * * @return array */ - public function compileParameters($console = false) + public function compileParameters(bool $console = false): array { if ($this->parameters) { $regex = '/(?=\S)[^\'"\s]*(?:\'[^\']*\'[^\'"\s]*|"[^"]*"[^\'"\s]*)*/'; @@ -131,9 +134,9 @@ public function compileParameters($console = false) /** * Results Relation. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function results() + public function results(): HasMany { return $this->hasMany(Result::class, 'task_id', 'id'); } @@ -141,9 +144,9 @@ public function results() /** * Returns the most recent result entry for this task. * - * @return Model|null + * @return Result|null */ - public function getLastResultAttribute() + public function getLastResultAttribute(): Result|null { return $this->results()->orderBy('id', 'desc')->first(); } @@ -151,7 +154,7 @@ public function getLastResultAttribute() /** * @return float */ - public function getAverageRuntimeAttribute() + public function getAverageRuntimeAttribute(): float { return $this->results()->avg('duration') ?? 0.00; } @@ -161,7 +164,7 @@ public function getAverageRuntimeAttribute() * * @return string */ - public function routeNotificationForMail() + public function routeNotificationForMail(): string { return $this->notification_email_address; } @@ -171,7 +174,7 @@ public function routeNotificationForMail() * * @return string */ - public function routeNotificationForNexmo() + public function routeNotificationForNexmo(): string { return $this->notification_phone_number; } @@ -181,7 +184,7 @@ public function routeNotificationForNexmo() * * @return string */ - public function routeNotificationForSlack() + public function routeNotificationForSlack(): string { return $this->notification_slack_webhook; } @@ -212,9 +215,9 @@ public function autoCleanup() /** * Create a new factory instance for the model. * - * @return \Illuminate\Database\Eloquent\Factories\Factory + * @return TotemTaskFactory */ - protected static function newFactory() + protected static function newFactory(): TotemTaskFactory { return TotemTaskFactory::new(); } diff --git a/src/Totem.php b/src/Totem.php index 82de81ee..cefae552 100644 --- a/src/Totem.php +++ b/src/Totem.php @@ -3,6 +3,8 @@ namespace Studio\Totem; use Closure; +use Illuminate\Http\Request; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Schema; @@ -14,18 +16,18 @@ class Totem /** * The callback that should be used to authenticate Totem users. * - * @var \Closure + * @var Closure */ - public static $authUsing; + public static Closure $authUsing; /** * Determine if the given request can access the Totem dashboard. * - * @param \Illuminate\Http\Request $request + * @param Request $request * * @return bool */ - public static function check($request) + public static function check(Request $request): bool { return (static::$authUsing ?: function () { return app()->environment('local'); @@ -35,7 +37,7 @@ public static function check($request) /** * Set the callback that should be used to authenticate Totem users. * - * @param \Closure $callback + * @param Closure $callback * * @return static */ @@ -51,7 +53,7 @@ public static function auth(Closure $callback) * * @return array */ - public static function frequencies() + public static function frequencies(): array { return config('totem.frequencies'); } @@ -59,9 +61,9 @@ public static function frequencies() /** * Return collection of Artisan commands filtered if needed. * - * @return \Illuminate\Support\Collection + * @return Collection */ - public static function getCommands() + public static function getCommands(): Collection { $command_filter = config('totem.artisan.command_filter'); $whitelist = config('totem.artisan.whitelist', true); diff --git a/src/TotemModel.php b/src/TotemModel.php index dddd7ef2..1a285975 100644 --- a/src/TotemModel.php +++ b/src/TotemModel.php @@ -10,9 +10,9 @@ class TotemModel extends Model protected $connection = TOTEM_DATABASE_CONNECTION; /** - * @return mixed + * @return string */ - public function getTable() + public function getTable(): string { if (Str::contains(parent::getTable(), TOTEM_TABLE_PREFIX)) { return parent::getTable(); diff --git a/src/Traits/FrontendSortable.php b/src/Traits/FrontendSortable.php index d24bd5d7..4540047d 100644 --- a/src/Traits/FrontendSortable.php +++ b/src/Traits/FrontendSortable.php @@ -7,11 +7,11 @@ trait FrontendSortable { /** - * @param \Illuminate\Database\Eloquent\Builder $builder + * @param Builder $builder * @param array $sortableColumns * @param array $defaultSort * - * @return \Illuminate\Database\Eloquent\Builder + * @return Builder */ public function scopeSortableBy(Builder $builder, array $sortableColumns, array $defaultSort = ['name' => 'asc']): Builder { diff --git a/src/Traits/HasFrequencies.php b/src/Traits/HasFrequencies.php index 5cc6be43..f2318ba4 100644 --- a/src/Traits/HasFrequencies.php +++ b/src/Traits/HasFrequencies.php @@ -4,6 +4,9 @@ use Closure; use Illuminate\Console\Scheduling\ManagesFrequencies; +use Illuminate\Contracts\Filesystem\FileNotFoundException; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Arr; use function json_decode; use function request; @@ -19,14 +22,14 @@ trait HasFrequencies * * @var array */ - protected $filters = []; + protected array $filters = []; /** * The array of reject callbacks. * * @var array */ - protected $rejects = []; + protected array $rejects = []; /** * Boot HasFrequencies Trait. @@ -85,9 +88,9 @@ public function beforeDelete() /** * Frequencies Relation. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function frequencies() + public function frequencies(): HasMany { return $this->hasMany(Frequency::class, 'task_id', 'id')->with('parameters'); } @@ -97,7 +100,7 @@ public function frequencies() * * @return string */ - public function getCronExpression() + public function getCronExpression(): string { if (! $this->expression) { $this->expression = '* * * * *'; @@ -119,10 +122,10 @@ public function getCronExpression() /** * Determine if the filters pass for the event. * - * @param \Illuminate\Contracts\Foundation\Application $app + * @param Application $app * @return bool */ - public function filtersPass($app) + public function filtersPass(Application $app): bool { foreach ($this->filters as $callback) { if (! $app->call($callback)) { @@ -142,10 +145,10 @@ public function filtersPass($app) /** * Register a callback to further filter the schedule. * - * @param \Closure $callback + * @param Closure $callback * @return $this */ - public function when(Closure $callback) + public function when(Closure $callback): static { $this->filters[] = $callback; @@ -159,7 +162,7 @@ public function when(Closure $callback) * @param string $endTime * @return $this */ - public function between($startTime, $endTime) + public function between($startTime, $endTime): static { return $this->when($this->inTimeInterval($startTime, $endTime)); } @@ -168,9 +171,9 @@ public function between($startTime, $endTime) * Process input data. If its an import action we must find out if the imported json has frequencies or not and * prepare data accordingly. * - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException + * @throws FileNotFoundException */ - private function processData() + private function processData(): array { $data = request()->all(); diff --git a/src/Traits/HasParameters.php b/src/Traits/HasParameters.php index bd0ee60e..682488e0 100644 --- a/src/Traits/HasParameters.php +++ b/src/Traits/HasParameters.php @@ -2,6 +2,8 @@ namespace Studio\Totem\Traits; +use Illuminate\Contracts\Filesystem\FileNotFoundException; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Arr; use Studio\Totem\Parameter; @@ -21,6 +23,9 @@ public static function bootHasParameters() }); } + /** + * @throws FileNotFoundException + */ public function afterSave() { $data = $this->processData(); @@ -42,9 +47,9 @@ public function beforeDelete() } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function parameters() + public function parameters(): HasMany { return $this->hasMany(Parameter::class); } @@ -53,9 +58,9 @@ public function parameters() * Process input data. If its an import action we must find out if the imported json has frequencies or not and * prepare data accordingly. * - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException + * @throws FileNotFoundException */ - private function processData() + private function processData(): array { $data = request()->all(); diff --git a/src/User.php b/src/User.php index 96f8f146..904b9a61 100644 --- a/src/User.php +++ b/src/User.php @@ -32,9 +32,9 @@ class User extends Authenticatable /** * Create a new factory instance for the model. * - * @return \Illuminate\Database\Eloquent\Factories\Factory + * @return TotemUserFactory */ - protected static function newFactory() + protected static function newFactory(): TotemUserFactory { return TotemUserFactory::new(); } From a3a882fb670f6b1d8151a8c96e6b1911f4a4fc60 Mon Sep 17 00:00:00 2001 From: "quentin.schmick" Date: Fri, 11 Feb 2022 16:05:14 -0500 Subject: [PATCH 3/8] Fixing styling --- src/Contracts/TaskInterface.php | 15 ++--- src/Events/Creating.php | 2 +- src/Events/Deleted.php | 1 - src/Events/Executed.php | 4 +- src/Events/TaskEvent.php | 2 +- src/Events/Updating.php | 4 +- .../Controllers/ActiveTasksController.php | 4 +- .../Controllers/ExecuteTasksController.php | 2 +- .../Controllers/ExportTasksController.php | 4 +- .../Controllers/ImportTasksController.php | 6 +- src/Http/Controllers/TasksController.php | 14 ++--- src/Http/Middleware/Authenticate.php | 4 +- src/Listeners/BuildCache.php | 4 +- src/Listeners/BustCache.php | 4 +- src/Listeners/BustCacheImmediately.php | 6 +- src/Listeners/Listener.php | 4 +- src/Repositories/EloquentTaskRepository.php | 61 +++++++++---------- src/Result.php | 1 - 18 files changed, 70 insertions(+), 72 deletions(-) diff --git a/src/Contracts/TaskInterface.php b/src/Contracts/TaskInterface.php index a9e9313f..a34d56f0 100644 --- a/src/Contracts/TaskInterface.php +++ b/src/Contracts/TaskInterface.php @@ -18,13 +18,14 @@ public function builder(): Builder; /** * Returns a task by its primary key. * - * @param int|Task $id + * @param int|Task $id * @return Task */ public function find(Task|int $id): Task; /** * Returns all tasks. + * * @return Collection */ public function findAll(): Collection; @@ -40,9 +41,9 @@ public function findAllActive(): Collection; * Creates a new task with the given data. * * @param array $input - * @return Task + * @return Task|bool */ - public function store(array $input); + public function store(array $input): Task|bool; /** * Updates the given task with the given data. @@ -56,7 +57,7 @@ public function update(array $input, Task $task): Task; /** * Deletes the given task. * - * @param int|Task $id + * @param int|Task $id * @return bool */ public function destroy(Task|int $id): bool; @@ -64,8 +65,8 @@ public function destroy(Task|int $id): bool; /** * Executes the given task. * - * @param int|Task $id - * @return bool + * @param int|Task $id + * @return Task */ - public function execute(Task|int $id): bool; + public function execute(Task|int $id): Task; } diff --git a/src/Events/Creating.php b/src/Events/Creating.php index 07e42ec4..27aacb37 100644 --- a/src/Events/Creating.php +++ b/src/Events/Creating.php @@ -20,7 +20,7 @@ class Creating implements ShouldBroadcast /** * Create a new event instance. * - * @param array $input + * @param array $input */ public function __construct(array $input) { diff --git a/src/Events/Deleted.php b/src/Events/Deleted.php index 572455e8..1d9d308e 100644 --- a/src/Events/Deleted.php +++ b/src/Events/Deleted.php @@ -6,7 +6,6 @@ class Deleted extends Event { /** * Create a new event instance. - * */ public function __construct() { diff --git a/src/Events/Executed.php b/src/Events/Executed.php index 935b9b53..b5dc6d69 100644 --- a/src/Events/Executed.php +++ b/src/Events/Executed.php @@ -10,8 +10,8 @@ class Executed extends BroadcastingEvent /** * Executed constructor. * - * @param Task $task - * @param string|float|int $started + * @param Task $task + * @param string|float|int $started * @param $output */ public function __construct(Task $task, $started, $output) diff --git a/src/Events/TaskEvent.php b/src/Events/TaskEvent.php index cb99e15e..a952eaed 100644 --- a/src/Events/TaskEvent.php +++ b/src/Events/TaskEvent.php @@ -18,7 +18,7 @@ class TaskEvent extends Event /** * Constructor. * - * @param Task $task + * @param Task $task */ public function __construct(Task $task) { diff --git a/src/Events/Updating.php b/src/Events/Updating.php index 41fecf2d..ee75f6ab 100644 --- a/src/Events/Updating.php +++ b/src/Events/Updating.php @@ -15,8 +15,8 @@ class Updating extends BroadcastingEvent /** * Create a new event instance. * - * @param array $input - * @param Task $task + * @param array $input + * @param Task $task */ public function __construct(array $input, Task $task) { diff --git a/src/Http/Controllers/ActiveTasksController.php b/src/Http/Controllers/ActiveTasksController.php index 596480fa..c5174b89 100644 --- a/src/Http/Controllers/ActiveTasksController.php +++ b/src/Http/Controllers/ActiveTasksController.php @@ -14,7 +14,7 @@ class ActiveTasksController extends Controller private TaskInterface $tasks; /** - * @param TaskInterface $tasks + * @param TaskInterface $tasks */ public function __construct(TaskInterface $tasks) { @@ -26,7 +26,7 @@ public function __construct(TaskInterface $tasks) /** * Store a newly active task in storage. * - * @param Request $request + * @param Request $request * @return JsonResponse */ public function store(Request $request): JsonResponse diff --git a/src/Http/Controllers/ExecuteTasksController.php b/src/Http/Controllers/ExecuteTasksController.php index 5a52fb64..f353a78f 100644 --- a/src/Http/Controllers/ExecuteTasksController.php +++ b/src/Http/Controllers/ExecuteTasksController.php @@ -13,7 +13,7 @@ class ExecuteTasksController extends Controller private TaskInterface $tasks; /** - * @param TaskInterface $tasks + * @param TaskInterface $tasks */ public function __construct(TaskInterface $tasks) { diff --git a/src/Http/Controllers/ExportTasksController.php b/src/Http/Controllers/ExportTasksController.php index 25ed463b..91b760eb 100644 --- a/src/Http/Controllers/ExportTasksController.php +++ b/src/Http/Controllers/ExportTasksController.php @@ -14,7 +14,7 @@ class ExportTasksController extends Controller /** * ExportTasksController constructor. - * @param TaskInterface $tasks + * @param TaskInterface $tasks */ public function __construct(TaskInterface $tasks) { @@ -28,7 +28,7 @@ public function __construct(TaskInterface $tasks) * * @return StreamedResponse */ - public function index() : StreamedResponse + public function index(): StreamedResponse { $headers = [ 'Content-Type' => 'text/json', diff --git a/src/Http/Controllers/ImportTasksController.php b/src/Http/Controllers/ImportTasksController.php index 5a2f4b5b..0709f9a7 100644 --- a/src/Http/Controllers/ImportTasksController.php +++ b/src/Http/Controllers/ImportTasksController.php @@ -15,7 +15,7 @@ class ImportTasksController extends Controller /** * ImportTasksController constructor. - * @param TaskInterface $tasks + * @param TaskInterface $tasks */ public function __construct(TaskInterface $tasks) { @@ -26,7 +26,9 @@ public function __construct(TaskInterface $tasks) /** * Import tasks from a json file. - * @param ImportRequest $request + * + * @param ImportRequest $request + * * @throws FileNotFoundException */ public function index(ImportRequest $request) diff --git a/src/Http/Controllers/TasksController.php b/src/Http/Controllers/TasksController.php index ea5699f0..93de52e3 100644 --- a/src/Http/Controllers/TasksController.php +++ b/src/Http/Controllers/TasksController.php @@ -21,7 +21,7 @@ class TasksController extends Controller /** * TasksController constructor. * - * @param TaskInterface $tasks + * @param TaskInterface $tasks */ public function __construct(TaskInterface $tasks) { @@ -35,7 +35,7 @@ public function __construct(TaskInterface $tasks) * * @return View */ - public function index() : View + public function index(): View { return view('totem::tasks.index', [ 'tasks' => $this->tasks @@ -89,7 +89,7 @@ public function store(TaskRequest $request): RedirectResponse /** * Display the specified task. * - * @param Task $task + * @param Task $task * @return Factory|View */ public function view(Task $task) @@ -102,7 +102,7 @@ public function view(Task $task) /** * Show the form for editing the specified task. * - * @param Task $task + * @param Task $task * @return View */ public function edit(Task $task): View @@ -122,8 +122,8 @@ public function edit(Task $task): View /** * Update the specified task in storage. * - * @param TaskRequest $request - * @param Task $task + * @param TaskRequest $request + * @param Task $task * @return RedirectResponse */ public function update(TaskRequest $request, Task $task): RedirectResponse @@ -138,7 +138,7 @@ public function update(TaskRequest $request, Task $task): RedirectResponse /** * Remove the specified task from storage. * - * @param Task $task + * @param Task $task * @return RedirectResponse */ public function destroy(Task $task) diff --git a/src/Http/Middleware/Authenticate.php b/src/Http/Middleware/Authenticate.php index 55ed6ce3..713302ec 100644 --- a/src/Http/Middleware/Authenticate.php +++ b/src/Http/Middleware/Authenticate.php @@ -12,8 +12,8 @@ class Authenticate /** * Handle the incoming request. * - * @param Request $request - * @param Closure $next + * @param Request $request + * @param Closure $next * @return Response */ public function handle(Request $request, Closure $next): Response diff --git a/src/Listeners/BuildCache.php b/src/Listeners/BuildCache.php index e1a0084d..6554733d 100644 --- a/src/Listeners/BuildCache.php +++ b/src/Listeners/BuildCache.php @@ -9,7 +9,7 @@ class BuildCache extends Listener /** * Handle the event. * - * @param Event $event + * @param Event $event */ public function handle(Event $event) { @@ -19,7 +19,7 @@ public function handle(Event $event) /** * Rebuild Cache. * - * @param Event $event + * @param Event $event */ protected function build(Event $event) { diff --git a/src/Listeners/BustCache.php b/src/Listeners/BustCache.php index 4ad769eb..1ec930a4 100644 --- a/src/Listeners/BustCache.php +++ b/src/Listeners/BustCache.php @@ -9,7 +9,7 @@ class BustCache extends Listener /** * Handle the event. * - * @param Event $event + * @param Event $event */ public function handle(Event $event) { @@ -19,7 +19,7 @@ public function handle(Event $event) /** * Clear Cache. * - * @param Event $event + * @param Event $event */ protected function clear(Event $event) { diff --git a/src/Listeners/BustCacheImmediately.php b/src/Listeners/BustCacheImmediately.php index e13c9257..1cd63fd4 100644 --- a/src/Listeners/BustCacheImmediately.php +++ b/src/Listeners/BustCacheImmediately.php @@ -15,7 +15,7 @@ class BustCacheImmediately /** * Create the event listener. * - * @param Container $app + * @param Container $app */ public function __construct(Container $app) { @@ -25,7 +25,7 @@ public function __construct(Container $app) /** * Handle the event. * - * @param Event $event + * @param Event $event */ public function handle(Event $event) { @@ -35,7 +35,7 @@ public function handle(Event $event) /** * Clear Cache. * - * @param Event $event + * @param Event $event */ protected function clear(Event $event) { diff --git a/src/Listeners/Listener.php b/src/Listeners/Listener.php index 8a07f557..6c899b20 100644 --- a/src/Listeners/Listener.php +++ b/src/Listeners/Listener.php @@ -21,8 +21,8 @@ class Listener implements ShouldQueue /** * Create the event listener. * - * @param Container $app - * @param TaskInterface $tasks + * @param Container $app + * @param TaskInterface $tasks */ public function __construct(Container $app, TaskInterface $tasks) { diff --git a/src/Repositories/EloquentTaskRepository.php b/src/Repositories/EloquentTaskRepository.php index 6a7635b9..eb20e573 100644 --- a/src/Repositories/EloquentTaskRepository.php +++ b/src/Repositories/EloquentTaskRepository.php @@ -3,6 +3,7 @@ namespace Studio\Totem\Repositories; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Cache; @@ -24,7 +25,7 @@ class EloquentTaskRepository implements TaskInterface /** * Return task eloquent builder. * - * @return Task + * @return Builder */ public function builder(): Builder { @@ -44,10 +45,10 @@ public function builder(): Builder /** * Find a task by id. * - * @param int|Task $id - * @return int|Task + * @param int|Task $id + * @return Task */ - public function find(Task|int $id) + public function find(Task|int $id): Task { if ($id instanceof Task) { return $id; @@ -61,9 +62,9 @@ public function find(Task|int $id) /** * Find all tasks. * - * @return mixed + * @return Collection */ - public function findAll() + public function findAll(): Collection { return Cache::rememberForever('totem.tasks.all', function () { return Task::query()->with('frequencies')->get(); @@ -73,9 +74,9 @@ public function findAll() /** * Find all active tasks. * - * @return mixed + * @return Collection */ - public function findAllActive() + public function findAllActive(): Collection { return Cache::rememberForever('totem.tasks.active', function () { return $this->findAll()->filter(function ($task) { @@ -87,16 +88,14 @@ public function findAllActive() /** * Create a new task. * - * @param array $input + * @param array $input * @return bool|Task */ - public function store(array $input) + public function store(array $input): bool|Task { $task = new Task; - if (Creating::dispatch($input) === false) { - return false; - } + Creating::dispatch($input); $task->fill(Arr::only($input, $task->getFillable()))->save(); @@ -108,17 +107,15 @@ public function store(array $input) /** * Update the given task. * - * @param array $input - * @param Task $task - * @return bool|int|Task + * @param array $input + * @param Task $task + * @return Task */ - public function update(array $input, $task) + public function update(array $input, $task): Task { $task = $this->find($task); - if (Updating::dispatch($input, $task) === false) { - return false; - } + Updating::dispatch($input, $task); $task->fill(Arr::only($input, $task->getFillable()))->save(); @@ -130,10 +127,10 @@ public function update(array $input, $task) /** * Delete the given task. * - * @param int|Task $id + * @param int|Task $id * @return bool */ - public function destroy(Task|int $id) + public function destroy(Task|int $id): bool { $task = $this->find($id); @@ -152,9 +149,9 @@ public function destroy(Task|int $id) * Activate the given task. * * @param $input - * @return int|Task + * @return Task */ - public function activate($input) + public function activate($input): Task { $task = $this->find($input['task_id']); @@ -166,12 +163,12 @@ public function activate($input) } /** - * Deactive the given task. + * Deactivate the given task. * * @param $id - * @return int|Task + * @return Task */ - public function deactivate($id) + public function deactivate($id): Task { $task = $this->find($id); @@ -185,10 +182,10 @@ public function deactivate($id) /** * Execute a given task. * - * @param int|Task $id - * @return int|Task + * @param int|Task $id + * @return Task */ - public function execute(Task|int $id) + public function execute(Task|int $id): Task { $task = $this->find($id); $start = microtime(true); @@ -208,9 +205,9 @@ public function execute(Task|int $id) * Import tasks. * * @param $input - * @return bool|int|Task|void + * @return void */ - public function import($input) + public function import($input): void { Cache::forget('totem.tasks.all'); Cache::forget('totem.tasks.active'); diff --git a/src/Result.php b/src/Result.php index fead8de4..ba39872d 100644 --- a/src/Result.php +++ b/src/Result.php @@ -3,7 +3,6 @@ namespace Studio\Totem; use Database\Factories\TotemResultFactory; -use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Query\Builder; From 2b16a10724767bf392fecac7181ce9ac29543d94 Mon Sep 17 00:00:00 2001 From: "quentin.schmick" Date: Fri, 11 Feb 2022 16:06:09 -0500 Subject: [PATCH 4/8] Fixing styling --- src/Task.php | 4 ++-- src/Totem.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Task.php b/src/Task.php index 387e94d3..e42951b3 100644 --- a/src/Task.php +++ b/src/Task.php @@ -67,6 +67,7 @@ public function getActivatedAttribute(): bool * Upcoming Accessor. * * @return string + * * @throws Exception */ public function getUpcomingAttribute(): string @@ -77,8 +78,7 @@ public function getUpcomingAttribute(): string /** * Convert a string of command arguments and options to an array. * - * @param bool $console if true will convert arguments to non associative array - * + * @param bool $console if true will convert arguments to non associative array * @return array */ public function compileParameters(bool $console = false): array diff --git a/src/Totem.php b/src/Totem.php index cefae552..5a41b84e 100644 --- a/src/Totem.php +++ b/src/Totem.php @@ -23,8 +23,7 @@ class Totem /** * Determine if the given request can access the Totem dashboard. * - * @param Request $request - * + * @param Request $request * @return bool */ public static function check(Request $request): bool From f9fbf94ca15e431392e6a52116459cdd2c4a7e92 Mon Sep 17 00:00:00 2001 From: Alban Horrocks Date: Fri, 6 May 2022 13:30:40 +0100 Subject: [PATCH 5/8] Laravel 9 tests and styling fixed (#327) * allow constraints * fix contract break * reverted types to get tests to pass * remove unneeded element Co-authored-by: James Freeman --- composer.json | 16 ++++++++-------- src/Contracts/TaskInterface.php | 2 +- src/Http/Middleware/Authenticate.php | 2 +- src/Http/Requests/ImportRequest.php | 6 ++++-- src/Repositories/EloquentTaskRepository.php | 2 +- src/Totem.php | 7 +++---- tests/Feature/TaskExecutionTest.php | 3 ++- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 3d08110d..d817732b 100644 --- a/composer.json +++ b/composer.json @@ -19,18 +19,18 @@ "php": "^8.0.0|^8.1.0", "ext-json": "*", "doctrine/dbal": "^3.1", - "illuminate/bus": "^8.11", - "illuminate/console": "^8.11", - "illuminate/contracts": "^8.11", - "illuminate/database": "^8.11", - "illuminate/events": "^8.11", - "illuminate/notifications": "^8.11", + "illuminate/bus": "^8.11|^9.0", + "illuminate/console": "^8.11|^9.0", + "illuminate/contracts": "^8.11|^9.0", + "illuminate/database": "^8.11|^9.0", + "illuminate/events": "^8.11|^9.0", + "illuminate/notifications": "^8.11|^9.0", "laravelcollective/html": "^6.0" }, "require-dev": { "mockery/mockery": "^1.0", - "orchestra/database": "^6.0", - "orchestra/testbench" : "^6.0", + "orchestra/database": "^6.0|^7.0", + "orchestra/testbench" : "^6.0|^7.0", "phpunit/phpunit": "^9.0" }, "suggest": { diff --git a/src/Contracts/TaskInterface.php b/src/Contracts/TaskInterface.php index a34d56f0..c955de24 100644 --- a/src/Contracts/TaskInterface.php +++ b/src/Contracts/TaskInterface.php @@ -21,7 +21,7 @@ public function builder(): Builder; * @param int|Task $id * @return Task */ - public function find(Task|int $id): Task; + public function find(Task|int $id); /** * Returns all tasks. diff --git a/src/Http/Middleware/Authenticate.php b/src/Http/Middleware/Authenticate.php index 713302ec..2da5c375 100644 --- a/src/Http/Middleware/Authenticate.php +++ b/src/Http/Middleware/Authenticate.php @@ -16,7 +16,7 @@ class Authenticate * @param Closure $next * @return Response */ - public function handle(Request $request, Closure $next): Response + public function handle($request, $next) { return Totem::check($request) ? $next($request) : abort(403); } diff --git a/src/Http/Requests/ImportRequest.php b/src/Http/Requests/ImportRequest.php index 6fb2a7dd..3c9632d6 100644 --- a/src/Http/Requests/ImportRequest.php +++ b/src/Http/Requests/ImportRequest.php @@ -51,6 +51,7 @@ public function messages() * * @param array|mixed $keys * @return array + * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function all($keys = null) @@ -68,9 +69,10 @@ public function all($keys = null) * Get the validated data from the request. * * @return array + * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ - public function validated() + public function validated($key = null, $default = null) { $content = ''; @@ -84,7 +86,7 @@ public function validated() /** * * Handle a failed validation attempt. * - * @param Validator $validator + * @param Validator $validator */ protected function failedValidation(Validator $validator) { diff --git a/src/Repositories/EloquentTaskRepository.php b/src/Repositories/EloquentTaskRepository.php index eb20e573..cd3a4f7f 100644 --- a/src/Repositories/EloquentTaskRepository.php +++ b/src/Repositories/EloquentTaskRepository.php @@ -48,7 +48,7 @@ public function builder(): Builder * @param int|Task $id * @return Task */ - public function find(Task|int $id): Task + public function find(Task|int $id) { if ($id instanceof Task) { return $id; diff --git a/src/Totem.php b/src/Totem.php index 5a41b84e..ab7fb709 100644 --- a/src/Totem.php +++ b/src/Totem.php @@ -23,10 +23,10 @@ class Totem /** * Determine if the given request can access the Totem dashboard. * - * @param Request $request + * @param Request|string|null $request * @return bool */ - public static function check(Request $request): bool + public static function check($request): bool { return (static::$authUsing ?: function () { return app()->environment('local'); @@ -36,8 +36,7 @@ public static function check(Request $request): bool /** * Set the callback that should be used to authenticate Totem users. * - * @param Closure $callback - * + * @param Closure $callback * @return static */ public static function auth(Closure $callback) diff --git a/tests/Feature/TaskExecutionTest.php b/tests/Feature/TaskExecutionTest.php index 7ea97aae..186a37ec 100644 --- a/tests/Feature/TaskExecutionTest.php +++ b/tests/Feature/TaskExecutionTest.php @@ -43,7 +43,8 @@ public function it_executes_a_scheduled_task() Event::fake(); - $this->get(route('totem.task.execute', $task->id)) + $this->signIn() + ->get(route('totem.task.execute', $task->id)) ->assertSuccessful(); $this->assertEquals(1, Result::count()); From 89fca438b11c39f510072821bb7c8c6b0da521f7 Mon Sep 17 00:00:00 2001 From: Alban Horrocks Date: Mon, 9 May 2022 22:50:17 +0100 Subject: [PATCH 6/8] Laravel 9 style fixes (#330) * more stytle fixes * fix style fix type * another style fix --- src/Http/Controllers/ExportTasksController.php | 1 + src/Http/Controllers/ImportTasksController.php | 1 + src/Http/Controllers/TasksController.php | 2 +- src/Traits/FrontendSortable.php | 7 +++---- src/Traits/HasFrequencies.php | 4 ++-- tests/Feature/ViewDashboardTest.php | 4 ++-- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Http/Controllers/ExportTasksController.php b/src/Http/Controllers/ExportTasksController.php index 91b760eb..4600c537 100644 --- a/src/Http/Controllers/ExportTasksController.php +++ b/src/Http/Controllers/ExportTasksController.php @@ -14,6 +14,7 @@ class ExportTasksController extends Controller /** * ExportTasksController constructor. + * * @param TaskInterface $tasks */ public function __construct(TaskInterface $tasks) diff --git a/src/Http/Controllers/ImportTasksController.php b/src/Http/Controllers/ImportTasksController.php index 0709f9a7..7ba764f7 100644 --- a/src/Http/Controllers/ImportTasksController.php +++ b/src/Http/Controllers/ImportTasksController.php @@ -15,6 +15,7 @@ class ImportTasksController extends Controller /** * ImportTasksController constructor. + * * @param TaskInterface $tasks */ public function __construct(TaskInterface $tasks) diff --git a/src/Http/Controllers/TasksController.php b/src/Http/Controllers/TasksController.php index 93de52e3..e17b9b7c 100644 --- a/src/Http/Controllers/TasksController.php +++ b/src/Http/Controllers/TasksController.php @@ -74,7 +74,7 @@ public function create(): View /** * Store a newly created task in storage. * - * @param TaskRequest $request + * @param TaskRequest $request * @return RedirectResponse */ public function store(TaskRequest $request): RedirectResponse diff --git a/src/Traits/FrontendSortable.php b/src/Traits/FrontendSortable.php index 4540047d..01339318 100644 --- a/src/Traits/FrontendSortable.php +++ b/src/Traits/FrontendSortable.php @@ -7,10 +7,9 @@ trait FrontendSortable { /** - * @param Builder $builder - * @param array $sortableColumns - * @param array $defaultSort - * + * @param Builder $builder + * @param array $sortableColumns + * @param array $defaultSort * @return Builder */ public function scopeSortableBy(Builder $builder, array $sortableColumns, array $defaultSort = ['name' => 'asc']): Builder diff --git a/src/Traits/HasFrequencies.php b/src/Traits/HasFrequencies.php index f2318ba4..a4f5b631 100644 --- a/src/Traits/HasFrequencies.php +++ b/src/Traits/HasFrequencies.php @@ -122,7 +122,7 @@ public function getCronExpression(): string /** * Determine if the filters pass for the event. * - * @param Application $app + * @param Application $app * @return bool */ public function filtersPass(Application $app): bool @@ -145,7 +145,7 @@ public function filtersPass(Application $app): bool /** * Register a callback to further filter the schedule. * - * @param Closure $callback + * @param Closure $callback * @return $this */ public function when(Closure $callback): static diff --git a/tests/Feature/ViewDashboardTest.php b/tests/Feature/ViewDashboardTest.php index d9dd8b13..1edb8ba5 100644 --- a/tests/Feature/ViewDashboardTest.php +++ b/tests/Feature/ViewDashboardTest.php @@ -80,8 +80,8 @@ public function view_dashboard_multiple_tasks_with_multiple_results() } /** - * @param int $task_count - * @param int $result_count + * @param int $task_count + * @param int $result_count * @return mixed */ private function _get_task_with_results($task_count = 1, $result_count = 1) From 08de5b9a296bde94bef7a8fccff6b2f196d6b720 Mon Sep 17 00:00:00 2001 From: "quentin.schmick" Date: Wed, 29 Jun 2022 10:45:34 -0400 Subject: [PATCH 7/8] Handle null is_active --- src/Task.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Task.php b/src/Task.php index 0d0a5070..08eff582 100644 --- a/src/Task.php +++ b/src/Task.php @@ -60,7 +60,7 @@ class Task extends TotemModel */ public function getActivatedAttribute(): bool { - return $this->is_active; + return $this->is_active ?? true; } /** From 6504f56e1d50af816c86adecc3116fab8113222a Mon Sep 17 00:00:00 2001 From: "quentin.schmick" Date: Wed, 29 Jun 2022 10:45:55 -0400 Subject: [PATCH 8/8] Fixing styling --- src/Traits/FrontendSortable.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Traits/FrontendSortable.php b/src/Traits/FrontendSortable.php index 0deabd0e..01339318 100644 --- a/src/Traits/FrontendSortable.php +++ b/src/Traits/FrontendSortable.php @@ -10,7 +10,6 @@ trait FrontendSortable * @param Builder $builder * @param array $sortableColumns * @param array $defaultSort - * * @return Builder */ public function scopeSortableBy(Builder $builder, array $sortableColumns, array $defaultSort = ['name' => 'asc']): Builder