Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AbstractController | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| extractFormData | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Phexium\Application; |
| 11 | |
| 12 | use Psr\Http\Message\ServerRequestInterface; |
| 13 | |
| 14 | abstract readonly class AbstractController implements ControllerInterface |
| 15 | { |
| 16 | protected function extractFormData(ServerRequestInterface $request, array $defaults): array |
| 17 | { |
| 18 | $data = (array) $request->getParsedBody(); |
| 19 | |
| 20 | $result = []; |
| 21 | |
| 22 | foreach ($defaults as $field => $defaultValue) { |
| 23 | $result[$field] = $data[$field] ?? $defaultValue; |
| 24 | } |
| 25 | |
| 26 | return $result; |
| 27 | } |
| 28 | } |