Completed
Push — master ( 2ec2e2...476664 )
by Joachim
05:23
created

Callback::getBodyFromRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Loevgaard\AltaPay\Callback;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
abstract class Callback implements CallbackInterface
8
{
9
    /**
10
     * @var ServerRequestInterface
11
     */
12
    protected $request;
13
14
    /**
15
     * @var array
16
     */
17
    protected $body;
18
19 24
    public function __construct(ServerRequestInterface $request)
20
    {
21 24
        $this->request = $request;
22 24
        $this->body = static::getBodyFromRequest($request);
23
24 24
        $this->init();
25 21
    }
26
27
    /**
28
     * Takes a ServerRequestInterface and returns the body as an array
29
     *
30
     * @param ServerRequestInterface $request
31
     * @return array
32
     */
33 45
    public static function getBodyFromRequest(ServerRequestInterface $request) : array
34
    {
35 45
        $body = $request->getParsedBody();
36 45
        return is_array($body) ? $body : [];
37
    }
38
}
39