Payload::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Api\Model;
4
5
/**
6
 * Class Payload.
7
 * Class represents json output that is sent to clients via REST API interface.
8
 *
9
 * Output is standardized and consists of error message (if applicable) and custom formatted content.
10
 * Example for index page:
11
 *
12
 * {
13
 *   "error": false,
14
 *   "content": "welcome to api."
15
 * }
16
 *
17
 * If there was an error, the reason should be described within error property.
18
 * HTTP status code is always 200, since server itself responded with no error.
19
 *
20
 * @package Api\Model
21
 */
22
class Payload
23
{
24
    private $error;
25
26
    private $content;
27
28
    public function __construct($content, $error = false)
29
    {
30
        $this->error = $error;
31
        $this->content = $content;
32
    }
33
34
    public function toArray()
35
    {
36
        return array(
37
            'error' => $this->error,
38
            'content' => $this->content
39
        );
40
    }
41
}