|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace WebmozartAssertBug117; |
| 6 | + |
| 7 | +use Webmozart\Assert\Assert; |
| 8 | +use function PHPStan\Testing\assertType; |
| 9 | + |
| 10 | +class HelloWorld |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @param mixed[] $requestData |
| 14 | + * |
| 15 | + * @return array{ |
| 16 | + * accountId: int, |
| 17 | + * errorColor: string|null, |
| 18 | + * theme: array{ |
| 19 | + * backgroundColor: string|null, |
| 20 | + * textColor: string|null, |
| 21 | + * headerImage: array{id: int}|null, |
| 22 | + * }, |
| 23 | + * } |
| 24 | + */ |
| 25 | + public function getData(int $accountId, array $requestData): array |
| 26 | + { |
| 27 | + Assert::keyExists($requestData, 'errorColor'); |
| 28 | + Assert::nullOrString($requestData['errorColor']); |
| 29 | + |
| 30 | + Assert::keyExists($requestData, 'theme'); |
| 31 | + Assert::isArray($requestData['theme']); |
| 32 | + |
| 33 | + Assert::keyExists($requestData['theme'], 'headerImage'); |
| 34 | + Assert::nullOrIsArray($requestData['theme']['headerImage']); |
| 35 | + |
| 36 | + if (null !== $requestData['theme']['headerImage']) { |
| 37 | + Assert::keyExists($requestData['theme']['headerImage'], 'id'); |
| 38 | + Assert::integer($requestData['theme']['headerImage']['id']); |
| 39 | + } |
| 40 | + |
| 41 | + Assert::keyExists($requestData, 'theme', 'backgroundColor'); |
| 42 | + Assert::nullOrString($requestData['theme']['backgroundColor']); |
| 43 | + |
| 44 | + Assert::keyExists($requestData, 'theme', 'textColor'); |
| 45 | + Assert::nullOrString($requestData['theme']['textColor']); |
| 46 | + |
| 47 | + $requestData['accountId'] = $accountId; |
| 48 | + |
| 49 | + assertType("hasOffsetValue('accountId', int)&hasOffsetValue('errorColor', string|null)&hasOffsetValue('theme', array&hasOffsetValue('backgroundColor', string|null)&hasOffsetValue('headerImage', (array&hasOffsetValue('id', int))|null)&hasOffsetValue('textColor', string|null))&non-empty-array", $requestData); |
| 50 | + |
| 51 | + return $requestData; |
| 52 | + } |
| 53 | +} |
0 commit comments