-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTraitProvidedToDtoRequest.php
More file actions
39 lines (32 loc) · 1001 Bytes
/
Copy pathTraitProvidedToDtoRequest.php
File metadata and controls
39 lines (32 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types = 1);
namespace App\Http\Requests;
use App\DataTransferObjects\StoreUserData;
use Illuminate\Foundation\Http\FormRequest;
// Trait-provided toDto() must satisfy the contract — the rule routes through
// PHPStan's hasNativeMethod(), which flattens trait-composed methods, mirroring
// the source-of-truth Pest test's method_exists() matcher. Pins the trait leg
// of the promise documented in the rule docblock, README, and CHANGELOG, which
// otherwise rests on an untested assumption about PHPStan internals.
trait ProvidesToDto
{
public function toDto(): StoreUserData
{
/** @var string $name */
$name = $this->validated()['name'];
return new StoreUserData($name);
}
}
final class TraitProvidedToDtoRequest extends FormRequest
{
use ProvidesToDto;
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'name' => ['required', 'string'],
];
}
}