Skip to content

Commit 6422a3b

Browse files
committed
update pint.json with additional rules for improved code quality and consistency
1 parent eb958ae commit 6422a3b

File tree

10 files changed

+45
-31
lines changed

10 files changed

+45
-31
lines changed

app/Actions/GetFormattedDateAction.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@
44

55
namespace App\Actions;
66

7-
use Carbon\Carbon;
8-
use DateTime;
7+
use Carbon\CarbonImmutable;
8+
use DateTimeImmutable;
99
use Exception;
1010

1111
class GetFormattedDateAction
1212
{
1313
/**
1414
* @throws Exception
1515
*/
16-
public function __invoke(null|string|Carbon $date): string
16+
public function __invoke(null|string|CarbonImmutable $date): string
1717
{
1818
if ($date === null) {
1919
return '';
2020
}
2121

22-
return is_string($date) ? (new DateTime($date))->format('Y-m-d') : $date->format('Y-m-d');
22+
if ($date instanceof CarbonImmutable) {
23+
return $date->format('Y-m-d');
24+
}
25+
26+
return (new DateTimeImmutable($date))->format('Y-m-d');
2327
}
2428
}

app/Actions/GetInitialsAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public function __invoke(?string $name = ''): string
1414

1515
$parts = explode(' ', $name);
1616

17-
$initials = strtoupper($parts[0][0] ?? '');
17+
$initials = mb_strtoupper($parts[0][0] ?? '');
1818

1919
if (count($parts) > 1) {
20-
$initials .= strtoupper(end($parts)[0] ?? '');
20+
$initials .= mb_strtoupper(end($parts)[0] ?? '');
2121
}
2222

2323
return $initials;

app/Actions/Images/StoreUploadedImageAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function __invoke(TemporaryUploadedFile|UploadedFile $image, string $dest
1515
$name = md5(random_int(1, 10).microtime()).'.jpg';
1616
$img = app(ResizeImageAction::class)($image, $width, $height);
1717

18-
$destinationFolder = rtrim($destinationFolder, DIRECTORY_SEPARATOR);
18+
$destinationFolder = mb_rtrim($destinationFolder, DIRECTORY_SEPARATOR);
1919

2020
Storage::disk($disk)->put($destinationFolder.DIRECTORY_SEPARATOR.$name, $img);
2121

app/Livewire/Admin/Users/Edit/Profile.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,6 @@ public function render(): View
4545
return view('livewire.admin.users.edit.profile');
4646
}
4747

48-
/**
49-
* @return array<string, array<int, string>>
50-
*/
51-
protected function rules(): array
52-
{
53-
return [
54-
'name' => [
55-
'required',
56-
'string',
57-
],
58-
'image' => [
59-
'nullable',
60-
'image',
61-
'mimes:png,jpg,gif',
62-
'max:5120',
63-
],
64-
'email' => [
65-
'required',
66-
'email',
67-
],
68-
];
69-
}
70-
7148
/**
7249
* @throws ValidationException
7350
*/
@@ -104,4 +81,27 @@ public function update(DeleteImageAction $deleteImageAction, StoreUploadedImageA
10481

10582
$this->dispatch('refreshAdminSettings');
10683
}
84+
85+
/**
86+
* @return array<string, array<int, string>>
87+
*/
88+
protected function rules(): array
89+
{
90+
return [
91+
'name' => [
92+
'required',
93+
'string',
94+
],
95+
'image' => [
96+
'nullable',
97+
'image',
98+
'mimes:png,jpg,gif',
99+
'max:5120',
100+
],
101+
'email' => [
102+
'required',
103+
'email',
104+
],
105+
];
106+
}
107107
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"stan": "phpstan analyse",
5555
"pest": "pest",
5656
"pest-type-coverage": "pest --type-coverage",
57-
"pest-coverage": "pest --coverage",
57+
"pest-coverage": "pest --parallel --coverage",
5858
"test": [
5959
"@pint",
6060
"@stan",

tests/Unit/App/Actions/GetFormattedDateActionTest.php

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

3+
declare(strict_types=1);
4+
35
use App\Actions\GetFormattedDateAction;
46

57
test('date is a carbon instance', function () {

tests/Unit/App/Actions/GetInitialsActionTest.php

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

3+
declare(strict_types=1);
4+
35
use App\Actions\GetInitialsAction;
46

57
test('can get initials', function (?string $value, string $expected) {

tests/Unit/App/Actions/Images/DeleteImageActionTest.php

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

3+
declare(strict_types=1);
4+
35
use App\Actions\Images\DeleteImageAction;
46
use Illuminate\Support\Facades\Storage;
57

tests/Unit/App/Actions/Images/ResizeImageActionTest.php

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

3+
declare(strict_types=1);
4+
35
use App\Actions\Images\ResizeImageAction;
46
use Illuminate\Http\Testing\File;
57
use Illuminate\Http\UploadedFile;

tests/Unit/App/Actions/Images/StoreUploadedImageActionTest.php

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

3+
declare(strict_types=1);
4+
35
use App\Actions\Images\ResizeImageAction;
46
use App\Actions\Images\StoreUploadedImageAction;
57
use Illuminate\Http\Testing\File;

0 commit comments

Comments
 (0)