Skip to content

Commit a3dbcdf

Browse files
tanhongitCopilot
andcommitted
fix: resolve PHPStan level 9 errors
- Simplify json payload parsing (remove redundant is_object/method_exists) - Add @var string annotation for field_type in WebhookService - Ensure payload is typed as array<string, mixed> before passing to services - Remove stale baseline patterns (route prefix, cast mixed) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 04b4586 commit a3dbcdf

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
- message: '#Parameter \#1 \$prefix of static method Illuminate\\Support\\Facades\\Route::prefix\(\) expects string, mixed given\.#'
4-
path: routes/*.php
5-
6-
- message: '#Part \$routePrefix \(mixed\) of encapsed string cannot be cast to string\.#'
7-
path: routes/*.php
8-
9-
- message: '#Cannot cast mixed to string#'
10-
path: src/*.php
11-
12-
- message: '#Cannot cast mixed to int#'
13-
path: src/*.php
14-
15-
- message: '#Cannot access offset .+ on mixed#'
16-
path: src/*.php
17-
183
- message: '#Parameter \#1 \$view of function view expects view-string\|null, string given\.#'
194
paths:
205
- src/Services/GithubService.php

src/Actions/GenerateCommentAction.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,17 @@ public function __invoke(Request $request, bool $validate = true): JsonResponse
2929

3030
try {
3131
if ($request->isJson()) {
32-
$jsonContent = $request->json();
33-
$payload = is_object($jsonContent) && method_exists($jsonContent, 'all')
34-
? $jsonContent->all()
35-
: (array) $jsonContent;
32+
/** @var array<string, mixed> $payload */
33+
$payload = $request->json()->all();
3634
} else {
37-
$payload = json_decode($request->getContent(), true);
35+
/** @var array<string, mixed> $payload */
36+
$payload = (array) json_decode($request->getContent(), true);
3837
}
3938

40-
if (!empty($payload['payload'])) {
39+
if (isset($payload['payload']) && is_array($payload['payload'])) {
4140
$payload = $payload['payload'];
4241
}
4342

44-
if (is_string($payload)) {
45-
$payload = json_decode($payload, true);
46-
}
47-
4843
if ($validate) {
4944
$validationResponse = $this->webhookService->validatePayloadForComment($payload);
5045
if ($validationResponse !== null) {

src/Services/WebhookService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected function hasValidNodeAndFieldData(array $payload): bool
4242
*/
4343
protected function hasFieldTemplate(array $payload): bool
4444
{
45+
/** @var string $fieldType */
4546
$fieldType = $payload['changes']['field_value']['field_type'] ?? '';
4647

4748
return view()->exists('github-project::md.field_types.'.$fieldType);

0 commit comments

Comments
 (0)