CommonBody::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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
21
declare(strict_types=1);
22
23
namespace Gnumoksha\FreeIpa\Infra\Rpc\Response;
24
25
class CommonBody implements Body
26
{
27
    /**
28
     * @var object|null
29
     */
30
    public $result;
31
    /**
32
     * @var string
33
     */
34
    public $principal;
35
    /**
36
     * @var mixed
37
     */
38
    public $error;
39
    /**
40
     * @var string|null
41
     */
42
    public $id;
43
    /**
44
     * @var string|null
45
     */
46
    public $version;
47
48
    public function __construct($result, string $principal, $error, ?string $id = null, ?string $version = null)
49
    {
50
        $this->result    = $result;
51
        $this->principal = $principal;
52
        $this->error     = $error;
53
        $this->id        = $id;
54
        $this->version   = $version;
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function getResult()
61
    {
62
        return $this->result;
63
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68
    public function getPrincipal(): string
69
    {
70
        return $this->principal;
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    public function hasError(): bool
77
    {
78
        return $this->error !== null;
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84
    public function getError()
85
    {
86
        return $this->error;
87
    }
88
89
    /**
90
     * {@inheritDoc}
91
     * @see \Gnumoksha\FreeIpa\Infra\Rpc\Request\CommonBody will send id as string
92
     */
93
    public function getId(): ?string
94
    {
95
        return $this->id;
96
    }
97
98
    /**
99
     * {@inheritDoc}
100
     */
101
    public function getVersion(): ?string
102
    {
103
        return $this->version;
104
    }
105
106
    /**
107
     * {@inheritDoc}
108
     */
109
    public function jsonSerialize()
110
    {
111
        return [
112
            'result'    => $this->result,
113
            'principal' => $this->principal,
114
            'error'     => $this->error,
115
            'id'        => $this->id,
116
            'version'   => $this->version,
117
        ];
118
    }
119
}
120