ApplicationHelper::getParams()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.9666
cc 2
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Selami\Helper;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
9
abstract class ApplicationHelper
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $args;
15
16
    /**
17
     * @var ServerRequestInterface
18
     */
19
    protected $request;
20
21
    protected function getParam(string $key, $default = null)
22
    {
23
        $postParams = $this->request->getParsedBody();
24
        $getParams = $this->request->getQueryParams();
25
        $return = $default;
26
        if (is_array($postParams) && array_key_exists($key, $postParams)) {
27
            $return = $postParams[$key];
28
        } elseif (is_object($postParams) && property_exists($postParams, $key)) {
29
            $return = $postParams->$key;
30
        } elseif (isset($getParams[$key])) {
31
            $return = $getParams[$key];
32
        }
33
        return $return;
34
    }
35
36
    protected function getParams() : array
37
    {
38
        $params = $this->request->getQueryParams();
39
        $postParams = $this->request->getParsedBody();
40
        if ($postParams) {
41
            $params = array_merge($params, (array)$postParams);
42
        }
43
        return $params;
44
    }
45
}
46