Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type correction #743

Merged
merged 20 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,18 @@ We test Moox using:

Please make sure you use the same tools in VS Code (our [VS Code Extension Pack](https://marketplace.visualstudio.com/items?itemName=adrolli.tallui-laravel-livewire-tailwind) covers this) or do the checks manually before committing to the dev-branch:

- PHPStan: `composer analyse ` or `./vendor/bin/phpstan analyse`, for packages `../../vendor/bin/phpstan analyse`
- Pest: `composer test ` or `./vendor/bin/pest`, for packages `../../vendor/bin/pest`
- Coverage: `composer test-coverage ` or `./vendor/bin/pest --coverage`, for packages `../../vendor/bin/pest --coverage`
- Pint: `composer format ` or `./vendor/bin/pint`, for packages `../../vendor/bin/pint`
- Use `composer lint` to do a dry run of Pint, aliased as `test:lint`
- Use `composer analyse` to run PHPStan, aliased as `analyze` and `test:types`
- Use `composer test` to run the complete test suite
- Use `composer test:refactor` to do a dry run of Rector
- Use `composer test:arch` to run the architecture tests
- Use `composer test:type-coverage` to run the type coverage tests
- Use `composer test:unit` to run pest parallel with coverage
- Use `composer test:coverage` to run pest with coverage
- Use `composer refactor` to run Rector (ATTENTION CHANGES FILES), aliased as `rector`
- Use `composer format` to run Pint (ATTENTION CHANGES FILES), aliased as `pint`

For more information, please see [composer.json](composer.json).

## Admin Navigation

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/BatchJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()
parent::__construct();
}

public function handle()
public function handle(): void
{
$this->info('Starting Moox Batch Job');

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/DemoJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()
parent::__construct();
}

public function handle()
public function handle(): void
{
$this->info('Starting Moox Demo Job');

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/FailJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()
parent::__construct();
}

public function handle()
public function handle(): void
{
$this->info('Starting Moox Fail Job');

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/LongJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()
parent::__construct();
}

public function handle()
public function handle(): void
{
$this->info('Starting Moox Long Job');

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/ShortJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()
parent::__construct();
}

public function handle()
public function handle(): void
{
$this->info('Starting Moox Short Job');

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/TimeoutJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()
parent::__construct();
}

public function handle()
public function handle(): void
{
$this->info('Starting Moox Timeout Job');

Expand Down
3 changes: 3 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Override;

class Kernel extends ConsoleKernel
{
Expand All @@ -12,6 +13,7 @@ class Kernel extends ConsoleKernel
*
* @return void
*/
#[Override]
protected function schedule(Schedule $schedule)
{
$schedule->command('moox:batchjob')->daily();
Expand All @@ -26,6 +28,7 @@ protected function schedule(Schedule $schedule)
*
* @return void
*/
#[Override]
protected function commands()
{
$this->load(__DIR__.'/Commands');
Expand Down
12 changes: 6 additions & 6 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Override;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
* @var array<class-string<Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
//
Expand All @@ -19,7 +20,7 @@ class Handler extends ExceptionHandler
/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<\Throwable>>
* @var array<int, class-string<Throwable>>
*/
protected $dontReport = [
//
Expand All @@ -38,12 +39,11 @@ class Handler extends ExceptionHandler

/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
#[Override]
public function register(): void
{
$this->reportable(function (Throwable $e) {
$this->reportable(function (Throwable $e): void {
//
});
}
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
use AuthorizesRequests;
use DispatchesJobs;
use ValidatesRequests;
}
68 changes: 45 additions & 23 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,29 @@

namespace App\Http;

use App\Http\Middleware\Authenticate;
use App\Http\Middleware\EncryptCookies;
use App\Http\Middleware\PreventRequestsDuringMaintenance;
use App\Http\Middleware\RedirectIfAuthenticated;
use App\Http\Middleware\TrimStrings;
use App\Http\Middleware\TrustProxies;
use App\Http\Middleware\ValidateSignature;
use App\Http\Middleware\VerifyCsrfToken;
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Auth\Middleware\EnsureEmailIsVerified;
use Illuminate\Auth\Middleware\RequirePassword;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
use Illuminate\Http\Middleware\HandleCors;
use Illuminate\Http\Middleware\SetCacheHeaders;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;

class Kernel extends HttpKernel
{
Expand All @@ -15,12 +37,12 @@ class Kernel extends HttpKernel
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
TrustProxies::class,
HandleCors::class,
PreventRequestsDuringMaintenance::class,
ValidatePostSize::class,
TrimStrings::class,
ConvertEmptyStringsToNull::class,
];

/**
Expand All @@ -30,18 +52,18 @@ class Kernel extends HttpKernel
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
],

'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
SubstituteBindings::class,
],
];

Expand All @@ -53,15 +75,15 @@ class Kernel extends HttpKernel
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'auth' => Authenticate::class,
'auth.basic' => AuthenticateWithBasicAuth::class,
'auth.session' => AuthenticateSession::class,
'cache.headers' => SetCacheHeaders::class,
'can' => Authorize::class,
'guest' => RedirectIfAuthenticated::class,
'password.confirm' => RequirePassword::class,
'signed' => ValidateSignature::class,
'throttle' => ThrottleRequests::class,
'verified' => EnsureEmailIsVerified::class,
];
}
7 changes: 6 additions & 1 deletion app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
use Override;

class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @param Request $request
* @return string|null
*/
#[Override]
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}

return response()->json(['message' => 'Unauthenticated.'], 401);
}
}
8 changes: 5 additions & 3 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@

use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param Closure(Request):((Response|RedirectResponse)) $next
* @param string|null ...$guards
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
* @return Response|RedirectResponse
*/
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
$guards = $guards === [] ? [null] : $guards;

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Middleware/TrustHosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustHosts as Middleware;
use Override;

class TrustHosts extends Middleware
{
Expand All @@ -11,6 +12,7 @@ class TrustHosts extends Middleware
*
* @return array<int, string|null>
*/
#[Override]
public function hosts()
{
return [
Expand Down
5 changes: 4 additions & 1 deletion app/Jobs/BatchJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

class BatchJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;

public function handle(): void
{
Expand Down
48 changes: 28 additions & 20 deletions app/Jobs/DemoJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,41 @@

class DemoJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, JobProgress, Queueable, SerializesModels;

public $tries;

public $timeout;

public $maxExceptions;

public $backoff;

public function __construct()
{
$this->tries = 10;
$this->timeout = 120;
$this->maxExceptions = 3;
$this->backoff = 240;
}

public function handle()
use Dispatchable;
use InteractsWithQueue;
use JobProgress;
use Queueable;
use SerializesModels;

/**
* @var int
*/
public $tries = 10;

/**
* @var int
*/
public $timeout = 120;

/**
* @var int
*/
public $maxExceptions = 3;

/**
* @var int
*/
public $backoff = 240;

public function handle(): void
{
$count = 0;
$steps = 10;
$final = 100;

while ($count < $final) {
$this->setProgress($count);
$count = $count + $steps;
$count += $steps;
sleep(10);
}
}
Expand Down
Loading