Skip to content

Commit

Permalink
Composer: Install & configure Rector and fix all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Bates committed Jan 22, 2024
1 parent fcee04e commit 35294ee
Show file tree
Hide file tree
Showing 28 changed files with 209 additions and 24 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ jobs:
- name: Run phpstan
run: composer run phpstan

rector:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- uses: actions/checkout@v4
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Run rector
run: composer run rector -- --dry-run

php-cs-fixer:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Back end:
* Laravel 10
* PHPStan (& Larastan) set to the highest level, as well as phpstan/phpstan-strict-rules for extra strictness
* PHPUnit 10
* Rector
* PHP CS Fixer configured to use the latest PER coding standards
* PHP_CodeSniffer configured to use the latest PSR12 coding standards

Expand Down
5 changes: 4 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

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

class Kernel extends ConsoleKernel
final class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
#[Override]
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
Expand All @@ -20,6 +22,7 @@ protected function schedule(Schedule $schedule): void
/**
* Register the commands for the application.
*/
#[Override]
protected function commands(): void
{
$this->load(__DIR__ . '/Commands');
Expand Down
4 changes: 3 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace App\Exceptions;

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

class Handler extends ExceptionHandler
final class Handler extends ExceptionHandler
{
/**
* The list of the inputs that are never flashed to the session on validation exceptions.
Expand All @@ -23,6 +24,7 @@ class Handler extends ExceptionHandler
/**
* Register the exception handling callbacks for the application.
*/
#[Override]
public function register(): void
{
$this->reportable(static function (Throwable $e): void {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
final class Controller extends BaseController
{
use AuthorizesRequests;
use ValidatesRequests;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
final class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

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

class Authenticate extends Middleware
final class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
#[Override]
protected function redirectTo(Request $request): ?string
{
return $request->expectsJson() ? null : \route('login');
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/EncryptCookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;

class EncryptCookies extends Middleware
final class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/PreventRequestsDuringMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;

class PreventRequestsDuringMaintenance extends Middleware
final class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class RedirectIfAuthenticated
final class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/TrimStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;

class TrimStrings extends Middleware
final class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Middleware/TrustHosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
namespace App\Http\Middleware;

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

class TrustHosts extends Middleware
final class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array<int, string|null>
*/
#[Override]
public function hosts(): array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;

class TrustProxies extends Middleware
final class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/ValidateSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Routing\Middleware\ValidateSignature as Middleware;

class ValidateSignature extends Middleware
final class ValidateSignature extends Middleware
{
/**
* The names of the query string parameters that should be ignored.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
final class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
Expand Down
2 changes: 1 addition & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
final class User extends Authenticatable
{
use HasApiTokens;
use HasFactory;
Expand Down
4 changes: 3 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\Translation\Translator;
use OutOfBoundsException;
use Override;

class AppServiceProvider extends ServiceProvider
final class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
#[Override]
public function register(): void
{
$this->app->resolving('translator', function (Translator $translator): void {
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
final class AuthServiceProvider extends ServiceProvider
{
/**
* The model to policy mappings for the application.
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/BroadcastServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;

class BroadcastServiceProvider extends ServiceProvider
final class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
Expand Down
5 changes: 4 additions & 1 deletion app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
use Override;

class EventServiceProvider extends ServiceProvider
final class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
Expand All @@ -25,6 +26,7 @@ class EventServiceProvider extends ServiceProvider
/**
* Register any events for your application.
*/
#[Override]
public function boot(): void
{
//
Expand All @@ -33,6 +35,7 @@ public function boot(): void
/**
* Determine if events and listeners should be automatically discovered.
*/
#[Override]
public function shouldDiscoverEvents(): bool
{
return false;
Expand Down
6 changes: 4 additions & 2 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
use Override;

class RouteServiceProvider extends ServiceProvider
final class RouteServiceProvider extends ServiceProvider
{
/**
* The path to your application's "home" route.
Expand All @@ -19,11 +20,12 @@ class RouteServiceProvider extends ServiceProvider
*
* @var string
*/
public const HOME = '/home';
final public const string HOME = '/home';

/**
* Define your route model bindings, pattern filters, and other route configuration.
*/
#[Override]
public function boot(): void
{
RateLimiter::for(
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"laravel/tinker": "^2.8"
},
"require-dev": {
"driftingly/rector-laravel": "^0.30.0",
"fakerphp/faker": "^1.9.1",
"friendsofphp/php-cs-fixer": "^3.47",
"larastan/larastan": "^2.8",
Expand All @@ -23,6 +24,7 @@
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^10.1",
"rector/rector": "^0.19.2",
"spatie/laravel-ignition": "^2.0",
"squizlabs/php_codesniffer": "^3.8"
},
Expand Down Expand Up @@ -74,6 +76,9 @@
"phpstan": [
"phpstan --ansi"
],
"rector": [
"rector process --ansi"
],
"php-cs-fixer": [
"php-cs-fixer fix --ansi"
],
Expand Down
Loading

0 comments on commit 35294ee

Please sign in to comment.