Skip to content

Commit

Permalink
Merge pull request #949 from daveroverts/rector
Browse files Browse the repository at this point in the history
chore: add rector
  • Loading branch information
daveroverts authored Feb 26, 2025
2 parents da5bf62 + 6f74037 commit 3702f80
Show file tree
Hide file tree
Showing 172 changed files with 951 additions and 1,206 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,20 @@ jobs:

- uses: ramsey/composer-install@v2

- name: "Restore result cache"
uses: actions/cache/restore@v4
with:
path: /tmp/phpstan # same as in phpstan.neon
key: "phpstan-result-cache-${{ github.run_id }}"
restore-keys: |
phpstan-result-cache-
- name: Run PHPStan
run: ./vendor/bin/phpstan analyse

- name: "Save result cache"
uses: actions/cache/save@v4
if: always()
with:
path: /tmp/phpstan # same as in phpstan.neon
key: "phpstan-result-cache-${{ github.run_id }}"
46 changes: 46 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Rector CI

on:
push:
branches:
- main
- next
- next-major
- beta
- alpha
- "*.x"
pull_request:
branches:
- '*'

jobs:
rector:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- uses: ramsey/composer-install@v2

- name: Rector Cache
uses: actions/cache@v4
with:
path: /tmp/rector
key: ${{ runner.os }}-rector-${{ github.run_id }}
restore-keys: ${{ runner.os }}-rector-

- run: mkdir -p /tmp/rector

- name: Rector Dry Run
run: php vendor/bin/rector process --dry-run --config=rector.php
10 changes: 5 additions & 5 deletions app/Console/Commands/EventCleanupReservationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ public function __construct()

/**
* Execute the console command.
*
* @return int
*/
public function handle()
public function handle(): int
{
$eventId = $this->argument('eventId');
if ($eventId) {
$event = Event::find($eventId);
if (!$event) {
$this->error("Could not find event with id {$eventId}");
$this->error('Could not find event with id ' . $eventId);
return Command::FAILURE;
}

EventCleanupReservationsJob::dispatch($event);
} else {
$this->withProgressBar(nextEvents(), function ($event) {
$this->withProgressBar(nextEvents(), function ($event): void {
EventCleanupReservationsJob::dispatch($event);
});
}

return Command::SUCCESS;
}
}
4 changes: 1 addition & 3 deletions app/Console/Commands/ImportAirportsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public function __construct()

/**
* Execute the console command.
*
* @return int
*/
public function handle()
public function handle(): int
{
ImportAirportsJob::dispatch();

Expand Down
1 change: 0 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Kernel extends ConsoleKernel
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down
5 changes: 2 additions & 3 deletions app/Events/BookingCancelled.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\User;
use App\Models\Booking;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
Expand All @@ -22,10 +23,8 @@ public function __construct(public Booking $booking, public User $user)

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
public function broadcastOn(): Channel
{
return new PrivateChannel('channel-name');
}
Expand Down
5 changes: 2 additions & 3 deletions app/Events/BookingChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Events;

use App\Models\Booking;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
Expand All @@ -22,10 +23,8 @@ public function __construct(public Booking $booking, public Collection $changes)

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
public function broadcastOn(): Channel
{
return new PrivateChannel('channel-name');
}
Expand Down
5 changes: 2 additions & 3 deletions app/Events/BookingConfirmed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Events;

use App\Models\Booking;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
Expand All @@ -21,10 +22,8 @@ public function __construct(public Booking $booking)

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
public function broadcastOn(): Channel
{
return new PrivateChannel('channel-name');
}
Expand Down
5 changes: 2 additions & 3 deletions app/Events/BookingDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\User;
use App\Models\Event;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
Expand All @@ -22,10 +23,8 @@ public function __construct(public Event $event, public User $user)

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
public function broadcastOn(): Channel
{
return new PrivateChannel('channel-name');
}
Expand Down
5 changes: 2 additions & 3 deletions app/Events/EventBulkEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Events;

use App\Models\Event;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
Expand All @@ -22,10 +23,8 @@ public function __construct(public Event $event, public array $request, public C

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
public function broadcastOn(): Channel
{
return new PrivateChannel('channel-name');
}
Expand Down
5 changes: 2 additions & 3 deletions app/Events/EventFinalInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Booking;
use App\Models\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
Expand All @@ -27,10 +28,8 @@ public function __construct(public Booking $booking, public ?User $testUser = nu

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
public function broadcastOn(): Channel
{
return new PrivateChannel('channel-name');
}
Expand Down
4 changes: 1 addition & 3 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ class Handler extends ExceptionHandler

/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register(): void
{
$this->reportable(function (Throwable $e) {
$this->reportable(function (Throwable $e): void {
//
});
}
Expand Down
7 changes: 5 additions & 2 deletions app/Exports/BookingsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function map($booking): array
if ($this->event->event_type_id == EventType::MULTIFLIGHTS->value) {
$flight1 = $booking->flights()->first();
$flight2 = $booking->flights()->whereKeyNot($flight1->id)->first();
if ($this->vacc) {
if ($this->vacc === true) {
return [
$booking->user->full_name,
$booking->user_id,
Expand All @@ -46,6 +46,7 @@ public function map($booking): array
$flight2->airportArr->icao,
];
}

return [
$booking->user->full_name,
$booking->user_id,
Expand All @@ -57,6 +58,7 @@ public function map($booking): array
$flight2->airportArr->icao,
];
}

$flight = $booking->flights->first();
return [
$booking->user->full_name,
Expand All @@ -74,12 +76,13 @@ public function map($booking): array

public function columnFormats(): array
{
if ($this->event->event_type_id == EventType::MULTIFLIGHTS->value && !$this->vacc) {
if ($this->event->event_type_id == EventType::MULTIFLIGHTS->value && $this->vacc !== true) {
return [
'E' => NumberFormat::FORMAT_DATE_TIME4,
'G' => NumberFormat::FORMAT_DATE_TIME4,
];
}

return [
'H' => NumberFormat::FORMAT_DATE_TIME4,
'I' => NumberFormat::FORMAT_DATE_TIME4,
Expand Down
9 changes: 2 additions & 7 deletions app/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function nextEvents($one = false, $showAll = false, $homepage = false, $withRela
if (!$showAll) {
$events = $events->where('is_online', true);
}

if ($homepage) {
$events = $events->where('show_on_homepage', true);
}
Expand All @@ -35,13 +36,7 @@ function nextEvents($one = false, $showAll = false, $homepage = false, $withRela
$events = $events->with($withRelations);
}

if ($one) {
$events = $events->first();
} else {
$events = $events->get();
}

return $events;
return $one ? $events->first() : $events->get();
}
}

Expand Down
26 changes: 13 additions & 13 deletions app/Http/Controllers/Airport/AirportAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function index(): View
{
$airports = Airport::with(['flightsDep', 'flightsArr', 'eventDep', 'eventArr'])
->paginate(100);
return view('airport.admin.overview', compact('airports'));
return view('airport.admin.overview', ['airports' => $airports]);
}

public function create(): View
Expand All @@ -32,24 +32,24 @@ public function create(): View
public function store(StoreAirport $request): RedirectResponse
{
$airport = Airport::create($request->validated());
flashMessage('success', __('Done'), __(':airport has been added!', ['airport' => "$airport->name [$airport->icao | $airport->iata]"]));
flashMessage('success', __('Done'), __(':airport has been added!', ['airport' => sprintf('%s [%s | %s]', $airport->name, $airport->icao, $airport->iata)]));
return to_route('admin.airports.index');
}

public function show(Airport $airport): View
{
return view('airport.admin.show', compact('airport'));
return view('airport.admin.show', ['airport' => $airport]);
}

public function edit(Airport $airport): View
{
return view('airport.admin.form', compact('airport'));
return view('airport.admin.form', ['airport' => $airport]);
}

public function update(UpdateAirport $request, Airport $airport): RedirectResponse
{
$airport->update($request->validated());
flashMessage('success', __('Done'), __(':airport has been updated!', ['airport' => "$airport->name [$airport->icao | $airport->iata]"]));
flashMessage('success', __('Done'), __(':airport has been updated!', ['airport' => sprintf('%s [%s | %s]', $airport->name, $airport->icao, $airport->iata)]));

return to_route('admin.airports.index');
}
Expand All @@ -58,17 +58,17 @@ public function destroy(Airport $airport): RedirectResponse
{
if ($airport->flightsDep->isEmpty() && $airport->flightsArr->isEmpty()) {
$airport->delete();
flashMessage('success', __('Done'), __(':airport has been deleted!', ['airport' => "$airport->name [$airport->icao | $airport->iata]"]));
flashMessage('success', __('Done'), __(':airport has been deleted!', ['airport' => sprintf('%s [%s | %s]', $airport->name, $airport->icao, $airport->iata)]));

return redirect()->back();
} else {
flashMessage(
'danger',
__('Warning'),
__(':airport could not be deleted! It\'s linked to another event', ['airport' => "$airport->name [$airport->icao | $airport->iata]"])
);
return redirect()->back();
}

flashMessage(
'danger',
__('Warning'),
__(":airport could not be deleted! It's linked to another event", ['airport' => sprintf('%s [%s | %s]', $airport->name, $airport->icao, $airport->iata)])
);
return redirect()->back();
}

public function destroyUnused()
Expand Down
Loading

0 comments on commit 3702f80

Please sign in to comment.