Skip to content

Commit 3bdeaa5

Browse files
tanhongitCopilot
andcommitted
refactor: optimize and clean github-project-php package
Bug fixes: - Fix ServiceProvider namespace (CSlant\GithubProject → CSlant\GitHubProject) - Fix double validatePayloadForComment() call in WebhookService - Fix lang copy-paste ('Hello from the blog core!' → proper message) - Remove redundant Cache::forget() after Cache::pull() - Remove dead array_map identity function in aggregateMessages() Security: - Remove stack trace/file/line leak in GenerateCommentAction error response Modernization: - Add declare(strict_types=1) to all PHP files - Constructor property promotion with readonly in all classes - Replace empty() with strict null/empty-string checks - Replace loose comparisons (!=, ==) with strict (!==, ===) in Blade - Replace (string) config() casts with @var string annotations - Use Illuminate\Http\Request consistently (not Symfony Request) - Use ->header() instead of raw server vars Architecture: - Dependency injection in ProcessAggregatedEvents (handle(GithubService)) - Simplify ServiceProvider: mergeConfigFrom() instead of scandir() loop - Remove empty registerCommands() method - Remove empty Constants/ and Http/ directories - Fix provides() return type (array, not ?array) - Add route names for all routes - Clean up PHPStan baseline (remove overly broad wildcards) Net: -133 lines removed Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 841d2da commit 3bdeaa5

18 files changed

+121
-254
lines changed

common/helpers.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
if (!function_exists('color_value_format')) {
46
/**
5-
* Format a value with an optional color.
6-
*
7-
* @param string $value
8-
* @param null|string $color
9-
* @return string
7+
* Format a value with an optional color using LaTeX syntax for GitHub Markdown.
108
*/
119
function color_value_format(string $value, ?string $color = null): string
1210
{
13-
if (empty($color)) {
11+
if ($color === null || $color === '') {
1412
return $value;
1513
}
1614

@@ -20,22 +18,17 @@ function color_value_format(string $value, ?string $color = null): string
2018

2119
if (!function_exists('format_date')) {
2220
/**
23-
* Format a date string.
24-
*
25-
* @param null|string $date
26-
* @param string $format
27-
*
28-
* @return null|string
21+
* Format a date string using Carbon.
2922
*/
3023
function format_date(?string $date, string $format = 'Y-m-d'): ?string
3124
{
32-
if (!$date) {
25+
if ($date === null || $date === '') {
3326
return null;
3427
}
3528

3629
try {
3730
return \Carbon\Carbon::parse($date)->format($format);
38-
} catch (\Exception $e) {
31+
} catch (\Exception) {
3932
return $date;
4033
}
4134
}

composer.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@
3636
}
3737
},
3838
"require": {
39-
"php": "^8.3",
39+
"php": "^8.4",
4040
"knplabs/github-api": "^3.16",
4141
"nyholm/psr7": "^1.8",
42-
"symfony/http-client": "^7.2"
42+
"symfony/http-client": "^8.0"
4343
},
4444
"require-dev": {
45-
"friendsofphp/php-cs-fixer": "^v3.0",
46-
"nunomaduro/collision": "^7.10",
47-
"nunomaduro/larastan": "^2.9",
48-
"orchestra/testbench": "^8.0",
49-
"pestphp/pest": "^2.0",
50-
"phpstan/extension-installer": "^1.3",
51-
"phpstan/phpstan-deprecation-rules": "^1.1",
52-
"phpstan/phpstan-phpunit": "^1.3"
45+
"friendsofphp/php-cs-fixer": "^v3.94",
46+
"nunomaduro/collision": "^8.9",
47+
"nunomaduro/larastan": "^3.9",
48+
"orchestra/testbench": "^10.0",
49+
"pestphp/pest": "^4.0",
50+
"phpstan/extension-installer": "^1.4",
51+
"phpstan/phpstan-deprecation-rules": "^2.0",
52+
"phpstan/phpstan-phpunit": "^2.0"
5353
},
5454
"scripts": {
5555
"a": "vendor/bin/phpstan analyse",

lang/en/github-project.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
return [
4-
'message' => 'Hello from the blog core!',
4+
'message' => 'GitHub Project notification package.',
55

66
'error' => [
77
'message' => 'An error occurred.',

phpstan-baseline.neon

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@ parameters:
33
- message: '#Parameter \#1 \$prefix of static method Illuminate\\Support\\Facades\\Route::prefix\(\) expects string, mixed given\.#'
44
path: routes/*.php
55

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
6+
- message: '#Parameter \#1 \$view of function view expects view-string\|null, string given\.#'
7+
paths:
8+
- src/Services/GithubService.php
9+
- src/Jobs/ProcessWebhookEvent.php
10+
- src/Jobs/ProcessAggregatedEvents.php

resources/views/md/field_types/date.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
$toValue = $toValue ? \Carbon\Carbon::parse($toValue)->format('Y-m-d') : null;
44
@endphp
55

6-
@if($fromValue != null && $toValue != null)
6+
@if($fromValue !== null && $toValue !== null)
77
**`{{ $fieldName }}`** has been changed:
88
- From **`{{ $fromValue }}`**
99
- To **`{{ $toValue }}`**.
10-
@elseif ($toValue == null)
10+
@elseif ($toValue === null)
1111
The value of **`{{ $fieldName }}`** has been removed.
1212
@else
1313
**`{{ $fieldName }}`** has been set to **`{{ $toValue }}`**.

resources/views/md/field_types/iteration.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@if($fromValue != null && $toValue != null)
1+
@if($fromValue !== null && $toValue !== null)
22
**`{{ $fieldName }}`** has been changed:
33
- From **`{{ $fromValue }}`**
44
- To **`{{ $toValue }}`**.
5-
@elseif ($toValue == null)
5+
@elseif ($toValue === null)
66
The value of **`{{ $fieldName }}`** has been removed.
77
@else
88
**`{{ $fieldName }}`** has been set to **`{{ $toValue }}`**.

resources/views/md/field_types/milestone.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@if($fromValue != null && $toValue != null)
1+
@if($fromValue !== null && $toValue !== null)
22
**`{{ $fieldName }}`** has been updated:
33
- From: **`{{ $fromValue['title'] }}`**
44
- To: **`{{ $toValue['title'] }}`**
5-
@elseif ($toValue == null)
5+
@elseif ($toValue === null)
66
**`{{ $fieldName }}`** has been removed from the issue.
77
@else
88
**`{{ $fieldName }}`** has been set to **`{{ $toValue['title'] }}`**.

resources/views/md/field_types/number.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
@if($fromValue != null && $toValue != null)
1+
@if($fromValue !== null && $toValue !== null)
22
**`{{ $fieldName }}`** has been changed From **`{{ $fromValue }}`** To **`{{ $toValue }}`**.
3-
@elseif ($toValue == null)
3+
@elseif ($toValue === null)
44
The value of **`{{ $fieldName }}`** has been removed.
55
@else
66
**`{{ $fieldName }}`** has been set to **`{{ $toValue }}`**.

resources/views/md/field_types/single_select.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
$toColor = $fieldData['to']['color'] ?? null;
44
@endphp
55

6-
@if($fromValue != null && $toValue != null)
6+
@if($fromValue !== null && $toValue !== null)
77
**`{{ $fieldName }}`** has been changed from {{ color_value_format($fromValue, $fromColor) }} to {{ color_value_format($toValue, $toColor) }}.
8-
@elseif ($toValue == null)
8+
@elseif ($toValue === null)
99
The value of **`{{ $fieldName }}`** has been removed.
1010
@else
1111
**`{{ $fieldName }}`** has been set to {{ color_value_format($toValue, $toColor) }}.

resources/views/md/field_types/text.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@if($fromValue != null && $toValue != null)
1+
@if($fromValue !== null && $toValue !== null)
22
**`{{ $fieldName }}`** has been changed:
33
- From **`{{ $fromValue }}`**
44
- To **`{{ $toValue }}`**.
5-
@elseif ($toValue == null)
5+
@elseif ($toValue === null)
66
The value of **`{{ $fieldName }}`** has been removed.
77
@else
88
**`{{ $fieldName }}`** has been set to **`{{ $toValue }}`**.

0 commit comments

Comments
 (0)