• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tomasnorre / crawler / 18356399208

08 Oct 2025 07:54PM UTC coverage: 69.666% (+0.4%) from 69.284%
18356399208

Pull #1198

github

web-flow
Merge f1aa53efd into 06fe2b9d2
Pull Request #1198: [TASK] Add RequestHelper to cleanup the BackendControllers

23 of 46 new or added lines in 4 files covered. (50.0%)

1920 of 2756 relevant lines covered (69.67%)

3.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/Classes/Controller/Backend/Helper/RequestHelper.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace AOE\Crawler\Controller\Backend\Helper;
6

7
/*
8
 * (c) 2025 Tomas Norre Mikkelsen <tomasnorre@gmail.com>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21

22
use Psr\Http\Message\ServerRequestInterface;
23

24
/**
25
 * @internal since 12.0.10
26
 */
27
final class RequestHelper
28
{
29
    public static function getIntFromRequest(ServerRequestInterface $request, string $key, int $default = 0): int
30
    {
31
        $body = $request->getParsedBody();
5✔
32
        $query = $request->getQueryParams();
5✔
33

34
        $value = (is_array($body) ? ($body[$key] ?? null) : null)
5✔
35
            ?? ($query[$key] ?? null)
5✔
36
            ?? $default;
3✔
37

38
        return (int) $value;
5✔
39
    }
40

41
    public static function getBoolFromRequest(ServerRequestInterface $request, string $key): bool
42
    {
43
        $body = $request->getParsedBody();
7✔
44
        $query = $request->getQueryParams();
7✔
45

46
        $value = (is_array($body) ? ($body[$key] ?? null) : null)
7✔
47
            ?? ($query[$key] ?? null);
5✔
48

49
        return !empty($value);
7✔
50
    }
51

52
    public static function getStringFromRequest(
53
        ServerRequestInterface $request,
54
        string $key,
55
        string $default = ''
56
    ): string {
57
        $body = $request->getParsedBody();
5✔
58
        $query = $request->getQueryParams();
5✔
59

60
        $value = (is_array($body) ? ($body[$key] ?? null) : null)
5✔
61
            ?? ($query[$key] ?? null)
5✔
62
            ?? $default;
3✔
63

64
        return is_scalar($value) ? (string) $value : $default;
5✔
65
    }
66

67
    public static function getArrayFromRequest(ServerRequestInterface $request, string $key): array
68
    {
69
        $body = $request->getParsedBody();
4✔
70
        $query = $request->getQueryParams();
4✔
71

72
        $source = is_array($body) ? $body : $query;
4✔
73
        $value = $source[$key] ?? $query[$key] ?? null;
4✔
74

75
        if (is_string($value)) {
4✔
NEW
76
            $value = json_decode($value, true);
×
77
        }
78

79
        return is_array($value) ? $value : [];
4✔
80
    }
81

82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc