Skip to content

Commit 6e516db

Browse files
Merge pull request #78 from swinn-io/chore/php-linting-formatting
build: modern PHP linting & formatting (Pint + Larastan)
2 parents c3c0f80 + 96a9992 commit 6e516db

108 files changed

Lines changed: 1735 additions & 943 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@ on:
55
pull_request:
66

77
jobs:
8+
quality:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Setup PHP 8.3
15+
uses: shivammathur/setup-php@v2
16+
with:
17+
php-version: '8.3'
18+
extensions: mbstring, pdo, pdo_mysql, xml, curl
19+
coverage: none
20+
21+
- name: Install Dependencies
22+
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
23+
24+
- name: Check formatting (Pint)
25+
run: vendor/bin/pint --test
26+
27+
- name: Static analysis (Larastan)
28+
run: vendor/bin/phpstan analyse --no-progress --memory-limit=1G
29+
830
tests:
931
runs-on: ubuntu-latest
1032

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ yarn-error.log
1919

2020
# Premature design briefs — kept locally, not part of the repo
2121
/docs/SWINN_DESIGN*.md
22+
/storage/phpstan
2223

2324
# Laravel Boost — regenerated per-developer via `php artisan boost:install`/`boost:update`
2425
/.claude

.styleci.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/Console/Kernel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Kernel extends ConsoleKernel
1010
/**
1111
* The Artisan commands provided by your application.
1212
*
13-
* @var array
13+
* @var array<int, class-string>
1414
*/
1515
protected $commands = [
1616
//
@@ -19,7 +19,6 @@ class Kernel extends ConsoleKernel
1919
/**
2020
* Define the application's command schedule.
2121
*
22-
* @param \Illuminate\Console\Scheduling\Schedule $schedule
2322
* @return void
2423
*/
2524
protected function schedule(Schedule $schedule)

app/Exceptions/Handler.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
namespace App\Exceptions;
44

55
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
6+
use Illuminate\Http\Request;
7+
use Symfony\Component\HttpFoundation\Response;
68
use Throwable;
79

810
class Handler extends ExceptionHandler
911
{
1012
/**
1113
* A list of the exception types that are not reported.
1214
*
13-
* @var array
15+
* @var array<int, class-string<Throwable>>
1416
*/
1517
protected $dontReport = [
1618
//
@@ -19,7 +21,7 @@ class Handler extends ExceptionHandler
1921
/**
2022
* A list of the inputs that are never flashed for validation exceptions.
2123
*
22-
* @var array
24+
* @var array<int, string>
2325
*/
2426
protected $dontFlash = [
2527
'password',
@@ -29,7 +31,6 @@ class Handler extends ExceptionHandler
2931
/**
3032
* Report or log an exception.
3133
*
32-
* @param \Throwable $exception
3334
* @return void
3435
*
3536
* @throws \Exception
@@ -42,11 +43,10 @@ public function report(Throwable $exception)
4243
/**
4344
* Render an exception into an HTTP response.
4445
*
45-
* @param \Illuminate\Http\Request $request
46-
* @param \Throwable $exception
47-
* @return \Symfony\Component\HttpFoundation\Response
46+
* @param Request $request
47+
* @return Response
4848
*
49-
* @throws \Throwable
49+
* @throws Throwable
5050
*/
5151
public function render($request, Throwable $exception)
5252
{

app/Exceptions/InvalidEnvelopeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ public function __construct(array $descriptor)
1111
{
1212
parent::__construct(response()->json($descriptor, 422));
1313
}
14-
}
14+
}

app/Http/Controllers/ContactController.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,25 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Http\Requests\ContactStoreRequest;
65
use App\Http\Resources\ContactResource;
76
use App\Interfaces\ContactServiceInterface;
87
use App\Interfaces\UserServiceInterface;
8+
use App\Models\User;
9+
use Illuminate\Contracts\Foundation\Application;
10+
use Illuminate\Http\RedirectResponse;
911
use Illuminate\Http\Request;
12+
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
13+
use Illuminate\Routing\Redirector;
1014
use Illuminate\Support\Facades\Auth;
1115

1216
class ContactController extends Controller
1317
{
14-
/**
15-
* @var ContactServiceInterface
16-
*/
1718
private ContactServiceInterface $service;
1819

19-
/**
20-
* @var UserServiceInterface
21-
*/
2220
private UserServiceInterface $userService;
2321

2422
/**
2523
* ContactController constructor.
26-
*
27-
* @param ContactServiceInterface $service
28-
* @param UserServiceInterface $userService
2924
*/
3025
public function __construct(ContactServiceInterface $service, UserServiceInterface $userService)
3126
{
@@ -36,11 +31,11 @@ public function __construct(ContactServiceInterface $service, UserServiceInterfa
3631
/**
3732
* Returns user by id.
3833
*
39-
* @param string $id
4034
* @return ContactResource
4135
*/
4236
public function show(string $id)
4337
{
38+
/** @var User $user */
4439
$user = Auth::user();
4540

4641
return new ContactResource(
@@ -51,23 +46,22 @@ public function show(string $id)
5146
/**
5247
* Returns contacts by user.
5348
*
54-
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
49+
* @return AnonymousResourceCollection
5550
*/
5651
public function index()
5752
{
53+
/** @var User $user */
5854
$user = Auth::user();
5955

6056
return ContactResource::collection($this->service->contacts($user));
6157
}
6258

6359
/**
6460
* Store a contact.
65-
*
66-
* @param string $user_id
67-
* @return ContactResource
6861
*/
6962
public function store(string $user_id): ContactResource
7063
{
64+
/** @var User $user */
7165
$user = Auth::user();
7266
$contact = $this->userService->find($user_id);
7367

@@ -79,21 +73,20 @@ public function store(string $user_id): ContactResource
7973
/**
8074
* Redirects to URI.
8175
*
82-
* @param Request $request
83-
* @param string $id
84-
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
76+
* @return Application|RedirectResponse|Redirector
8577
*/
8678
public function redirect(Request $request, string $id)
8779
{
80+
/** @var User $user */
8881
$user = Auth::user();
8982
$contact = $this->service->contact($id, $user);
9083

91-
if (null === $contact) {
84+
if ($contact === null) {
9285
abort(404);
9386
}
9487

9588
$URI = $request->get('redirect_uri', config('app.uri'));
9689

97-
return redirect($URI ?? '/');
90+
return redirect(is_string($URI) ? $URI : '/');
9891
}
9992
}

app/Http/Controllers/FrontEnd/DashboardController.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44

55
use App\Http\Controllers\Controller;
66
use App\Interfaces\MessageServiceInterface;
7+
use App\Models\User;
78
use Illuminate\Http\Request;
89
use Illuminate\Support\Facades\Auth;
10+
use Illuminate\View\View;
11+
912
use function view;
1013

1114
class DashboardController extends Controller
1215
{
1316
/**
1417
* Display a listing of the resource.
1518
*
16-
* @return \Illuminate\Http\Response
19+
* @return View
1720
*/
1821
public function index(MessageServiceInterface $messages)
1922
{
23+
/** @var User $user */
2024
$user = Auth::user();
2125
$threads = $messages->threads($user);
2226

@@ -26,7 +30,7 @@ public function index(MessageServiceInterface $messages)
2630
'subject' => $thread->subject,
2731
'unread_count' => 0,
2832
'participants' => $thread->participants
29-
->map(fn ($participant) => ['user' => ['name' => $participant->user->name]])
33+
->map(fn ($participant) => ['user' => ['name' => $participant->user?->name]])
3034
->values()
3135
->all(),
3236
])->values()->all(),
@@ -36,7 +40,7 @@ public function index(MessageServiceInterface $messages)
3640
/**
3741
* Show the form for creating a new resource.
3842
*
39-
* @return \Illuminate\Http\Response
43+
* @return void
4044
*/
4145
public function create()
4246
{
@@ -46,8 +50,7 @@ public function create()
4650
/**
4751
* Store a newly created resource in storage.
4852
*
49-
* @param \Illuminate\Http\Request $request
50-
* @return \Illuminate\Http\Response
53+
* @return void
5154
*/
5255
public function store(Request $request)
5356
{
@@ -58,7 +61,7 @@ public function store(Request $request)
5861
* Display the specified resource.
5962
*
6063
* @param int $id
61-
* @return \Illuminate\Http\Response
64+
* @return void
6265
*/
6366
public function show($id)
6467
{
@@ -69,7 +72,7 @@ public function show($id)
6972
* Show the form for editing the specified resource.
7073
*
7174
* @param int $id
72-
* @return \Illuminate\Http\Response
75+
* @return void
7376
*/
7477
public function edit($id)
7578
{
@@ -79,9 +82,8 @@ public function edit($id)
7982
/**
8083
* Update the specified resource in storage.
8184
*
82-
* @param \Illuminate\Http\Request $request
8385
* @param int $id
84-
* @return \Illuminate\Http\Response
86+
* @return void
8587
*/
8688
public function update(Request $request, $id)
8789
{
@@ -92,7 +94,7 @@ public function update(Request $request, $id)
9294
* Remove the specified resource from storage.
9395
*
9496
* @param int $id
95-
* @return \Illuminate\Http\Response
97+
* @return void
9698
*/
9799
public function destroy($id)
98100
{

app/Http/Controllers/FrontEnd/PageController.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
use App\Http\Controllers\Controller;
66
use Illuminate\Http\Request;
7+
use Illuminate\View\View;
78

89
class PageController extends Controller
910
{
1011
/**
1112
* Display a listing of the resource.
1213
*
13-
* @return \Illuminate\Http\Response
14+
* @return View
1415
*/
1516
public function index()
1617
{
@@ -20,7 +21,7 @@ public function index()
2021
/**
2122
* Show the form for creating a new resource.
2223
*
23-
* @return \Illuminate\Http\Response
24+
* @return void
2425
*/
2526
public function create()
2627
{
@@ -30,8 +31,7 @@ public function create()
3031
/**
3132
* Store a newly created resource in storage.
3233
*
33-
* @param \Illuminate\Http\Request $request
34-
* @return \Illuminate\Http\Response
34+
* @return void
3535
*/
3636
public function store(Request $request)
3737
{
@@ -42,7 +42,7 @@ public function store(Request $request)
4242
* Display the specified resource.
4343
*
4444
* @param int $id
45-
* @return \Illuminate\Http\Response
45+
* @return void
4646
*/
4747
public function show($id)
4848
{
@@ -53,7 +53,7 @@ public function show($id)
5353
* Show the form for editing the specified resource.
5454
*
5555
* @param int $id
56-
* @return \Illuminate\Http\Response
56+
* @return void
5757
*/
5858
public function edit($id)
5959
{
@@ -63,9 +63,8 @@ public function edit($id)
6363
/**
6464
* Update the specified resource in storage.
6565
*
66-
* @param \Illuminate\Http\Request $request
6766
* @param int $id
68-
* @return \Illuminate\Http\Response
67+
* @return void
6968
*/
7069
public function update(Request $request, $id)
7170
{
@@ -76,7 +75,7 @@ public function update(Request $request, $id)
7675
* Remove the specified resource from storage.
7776
*
7877
* @param int $id
79-
* @return \Illuminate\Http\Response
78+
* @return void
8079
*/
8180
public function destroy($id)
8281
{

0 commit comments

Comments
 (0)