CommonBodyBuilder   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 13 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