Skip to content

Commit 1b3529d

Browse files
Increase to Psalm level 5
Signed-off-by: Christoph Wurst <[email protected]>
1 parent ad18c1a commit 1b3529d

File tree

9 files changed

+31
-13
lines changed

9 files changed

+31
-13
lines changed

Diff for: app/Contracts/WineHandler.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
namespace App\Contracts;
2222

2323
use App\Exceptions\InvalidCompetitionStateException;
24+
use App\Exceptions\ValidationException;
2425
use App\MasterData\Competition;
2526
use App\MasterData\User;
2627
use App\Wine;
2728
use Illuminate\Http\UploadedFile;
2829
use Illuminate\Pagination\Paginator;
29-
use Illuminate\Validation\ValidationException;
3030

3131
interface WineHandler
3232
{
@@ -66,6 +66,10 @@ public function importKdb(UploadedFile $file, Competition $competition);
6666
public function importExcluded(UploadedFile $file, Competition $competition);
6767

6868
/**
69+
* @param Wine $wine
70+
* @param array $data
71+
* @throws ValidationException
72+
*/
6973
public function updateSosi(Wine $wine, array $data);
7074

7175
/**

Diff for: app/Http/Controllers/CatalogueController.php

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use App\Contracts\WineHandler;
2424
use App\MasterData\Competition;
25+
use App\MasterData\User;
2526
use Illuminate\Support\Facades\Auth;
2627
use Illuminate\Support\Facades\Response;
2728
use Symfony\Component\HttpFoundation\BinaryFileResponse;
@@ -87,6 +88,7 @@ public function tastingCatalogue(Competition $competition, WineHandler $wineHand
8788
{
8889
$this->authorize('create-tasting-catalogue', $competition);
8990

91+
/** @var User $user */
9092
$user = Auth::user();
9193
if ($user->isAdmin()) {
9294
$wines = $competition

Diff for: app/Http/Controllers/CompetitionController.php

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use App\MasterData\Association;
2727
use App\MasterData\Competition;
2828
use App\MasterData\CompetitionState;
29+
use App\MasterData\User;
2930
use App\Tasting\TastingStage;
3031
use App\WinesChosenSignedOff;
3132
use function array_map;
@@ -255,6 +256,7 @@ public function showSignChosen(Competition $competition)
255256
{
256257
$this->authorize('sign-chosen', $competition);
257258

259+
/** @var User $user */
258260
$user = Auth::user();
259261
if ($user->isAdmin()) {
260262
$associations = Association::all();

Diff for: app/Http/Controllers/WineController.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use App\MasterData\Applicant;
2828
use App\MasterData\Competition;
2929
use App\MasterData\CompetitionState;
30+
use App\MasterData\User;
3031
use App\MasterData\WineSort;
3132
use App\Wine;
3233
use App\Wine\EnrollmentForm;
@@ -236,6 +237,7 @@ public function store(Competition $competition, Request $request): RedirectRespo
236237
unset($data['winequality_id']);
237238
}
238239

240+
/** @var User $user */
239241
$user = Auth::user();
240242
if (! $competition->administrates($user)) {
241243
//TODO: move to validation
@@ -335,6 +337,7 @@ public function update(Wine $wine, Request $request): RedirectResponse
335337
$data['winequality_id'] = null;
336338
}
337339

340+
/** @var User $user */
338341
$user = Auth::user();
339342
if (! $wine->competition->administrates($user)) {
340343
// TODO: move to validation
@@ -364,13 +367,15 @@ public function update(Wine $wine, Request $request): RedirectResponse
364367
* Show confirmation dialog for deleting the wine.
365368
*
366369
* @param Wine $wine
367-
* @return Resp
370+
* @return View
368371
*/
369372
public function delete(Wine $wine)
370373
{
371374
$this->authorize('delete-wine', $wine);
372375

373-
return $this->viewFactory->make('competition/wines/delete')->withWine($wine);
376+
return $this->viewFactory
377+
->make('competition/wines/delete')
378+
->with('wine', $wine);
374379
}
375380

376381
/**

Diff for: app/MasterData/CompetitionState.php

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function getDescription()
8787
default:
8888
Log::error('unknown competition state '.$this->description);
8989
App::abort(500);
90+
return 'IMPOSSIBLE';
9091
}
9192
}
9293
}

Diff for: app/MasterData/User.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ public function getEmailForPasswordReset()
239239
// User is assoc admin -> only check assocs
240240
$first = $this->associations()->whereNotNull('email')->first();
241241
if (is_null($first)) {
242-
return null;
242+
throw new \Exception("No email set for association");
243243
}
244244

245245
return $first->email;
246246
} else {
247247
// User might be applicant admin -> check those
248248
$first = $this->applicants()->whereNotNull('email')->first();
249249
if (is_null($first)) {
250-
return null;
250+
throw new \Exception("No email set for applicant");
251251
}
252252

253253
return $first->email;

Diff for: app/Validation/FileValidator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function validate()
8787
];
8888
$validator = BaseValidator::make($data, $rules, $this->getErrorMessages(), $names);
8989
if ($validator->fails()) {
90-
throw new ValidationException($validator->messages());
90+
throw new ValidationException($validator->errors());
9191
}
9292
}
9393
}

Diff for: app/Wine/Handler.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ public function create(array $data, Competition $competition)
7373

7474
$validator = new WineValidator($data);
7575
$validator->setCompetition($competition);
76-
$validator->setUser(Auth::user());
76+
/** @var User $user */
77+
$user = Auth::user();
78+
$validator->setUser($user);
7779
$validator->validateCreate();
7880
$wine = new Wine($data);
7981

@@ -117,7 +119,9 @@ public function update(Wine $wine, array $data)
117119

118120
$validator = $this->validatorFactory->newWineValidator($wine, $data);
119121
$validator->setCompetition($wine->competition);
120-
$validator->setUser(Auth::user());
122+
/** @var User $user */
123+
$user = Auth::user();
124+
$validator->setUser($user);
121125
$validator->validateUpdate();
122126

123127
if (isset($data['kdb']) && $wine->kdb !== $data['kdb'] && $competitionState->id !== CompetitionState::STATE_KDB) {
@@ -142,10 +146,10 @@ public function update(Wine $wine, array $data)
142146
]);
143147
if ($wine->isDirty($enrollmentAttributes)) {
144148
// These attributes may only be changed via enrollment while 'nr' is not set or by an admin
145-
if ($competitionState->id !== CompetitionState::STATE_ENROLLMENT && ! Auth::user()->isAdmin()) {
149+
if ($competitionState->id !== CompetitionState::STATE_ENROLLMENT && ! $user->isAdmin()) {
146150
throw new WineLockedException();
147151
}
148-
if ($competitionState->id === CompetitionState::STATE_ENROLLMENT && ! is_null($wine->nr) && ! Auth::user()->isAdmin()) {
152+
if ($competitionState->id === CompetitionState::STATE_ENROLLMENT && ! is_null($wine->nr) && ! $user->isAdmin()) {
149153
throw new WineLockedException();
150154
}
151155
}
@@ -186,7 +190,7 @@ public function updateKdb(Wine $wine, array $data)
186190
{
187191
$validator = Validator::make($data, ['value' => 'required|boolean']);
188192
if ($validator->fails()) {
189-
throw new ValidationException($validator->messages());
193+
throw new ValidationException($validator->errors());
190194
}
191195

192196
$this->wineRepository->update($wine, [
@@ -314,7 +318,7 @@ public function updateSosi(Wine $wine, array $data)
314318
{
315319
$validator = \Validator::make($data, ['value' => 'required|boolean']);
316320
if ($validator->fails()) {
317-
throw new ValidationException($validator->messages());
321+
throw new ValidationException($validator->errors());
318322
}
319323

320324
$this->wineRepository->update($wine, [

Diff for: psalm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="6"
3+
errorLevel="5"
44
resolveFromConfigFile="true"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"

0 commit comments

Comments
 (0)