CommonBodyBuilder::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
rs 9.9666
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * FreeIPA library for PHP
5
 * Copyright (C) 2015-2019 Tobias Sette <[email protected]>
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
declare(strict_types=1);
21
22
namespace Gnumoksha\FreeIpa\Infra\Rpc\Response;
23
24
use Gnumoksha\FreeIpa\Infra\Json\Json;
25
use Psr\Http\Message\ResponseInterface;
26
27
class CommonBodyBuilder implements BodyBuilder
28
{
29
    /**
30
     * @throws \Gnumoksha\FreeIpa\Infra\Json\JsonException
31
     */
32
    public function build(ResponseInterface $response): Body
33
    {
34
        $body = $response->getBody();
35
        $body->rewind();
36
        $jsonResponse = (object)Json::decode($body->getContents());
37
38
        // #TODO handle results fields: count, total, summary, result
39
        return new CommonBody(
40
            $jsonResponse->result,
41
            $jsonResponse->principal,
42
            $jsonResponse->error,
43
            $jsonResponse->id,
44
            $jsonResponse->version
45
        );
46
    }
47
}
48