Passed
Push — master ( e3c67b...98eade )
by Fran
08:10
created

JsonResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 46
ccs 8
cts 8
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 4
1
<?php
2
namespace PSFS\base\dto;
3
4
class JsonResponse extends Dto
5
{
6
    /**
7
     * Response message
8
     * @var string $message
9
     */
10
    public $message = 'No message';
11
    /**
12
     * Response result
13
     * @var bool $success
14
     */
15
    public $success = false;
16
    /**
17
     * Data of response
18
     * @var array $data
19
     */
20
    public $data = null;
21
    /**
22
     * Number of total results
23
     * @var int total
24
     */
25
    public $total = 0;
26
    /**
27
     * Number of pages availables
28
     * @var int pages
29
     */
30
    public $pages = 1;
31
32
    /**
33
     * JsonResponse constructor.
34
     * @param array $data
35
     * @param bool $result
36
     * @param null $total
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $total is correct as it would always require null to be passed?
Loading history...
37
     * @param int $pages
38
     * @param null $message
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $message is correct as it would always require null to be passed?
Loading history...
39
     * @throws \PSFS\base\exception\GeneratorException
40
     */
41 1
    public function __construct($data = array(), $result = false, $total = null, $pages = 1, $message = null)
42
    {
43 1
        parent::__construct(false);
44 1
        $this->data = $data;
45 1
        $this->success = $result;
46 1
        $this->total = $total ?: (is_array($data) ? count($data) : 0);
0 ignored issues
show
introduced by
$total is of type null, thus it always evaluated to false.
Loading history...
introduced by
The condition is_array($data) is always true.
Loading history...
47 1
        $this->pages = $pages;
48 1
        if(null !== $message) {
0 ignored issues
show
introduced by
The condition null !== $message is always false.
Loading history...
49 1
            $this->message = $message;
50
        }
51
    }
52
}