Passed
Pull Request — master (#33)
by Melech
05:54 queued 02:40
created

getParamFromRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Routing\Middleware;
15
16
use RuntimeException;
17
use Valkyrja\Http\JsonRequest;
18
use Valkyrja\Http\Request;
19
20
/**
21
 * Class ValidateParsedBodyRequestMiddleware.
22
 *
23
 * @author Melech Mizrachi
24
 */
25
abstract class ValidateJsonParamsRequestMiddleware extends ValidateRequestMiddleware
26
{
27
    use ValidateParamRequestTrait;
28
29
    /**
30
     * @inheritDoc
31
     */
32
    protected static function getParamFromRequest(JsonRequest|Request $request, string $param): mixed
33
    {
34
        if (! is_a($request, JsonRequest::class)) {
35
            throw new RuntimeException('Json Request is required for this to work.');
36
        }
37
38
        return $request->getParsedJsonParam($param);
39
    }
40
}
41