Completed
Push — master ( ad3b69...02c092 )
by John
09:08 queued 05:48
created

ApiResponseErrorException::__construct()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 13
nc 5
nop 3
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Test;
10
11
/**
12
 * @author John Kleijn <[email protected]>
13
 */
14
class ApiResponseErrorException extends \Exception
15
{
16
    /**
17
     * @var \stdClass
18
     */
19
    private $data;
20
21
    /**
22
     * @var string
23
     */
24
    private $content;
25
26
    /**
27
     * @param string    $content
28
     * @param \stdClass $data
29
     * @param int       $httpStatusCode
30
     */
31
    public function __construct(string $content, \stdClass $data, int $httpStatusCode)
32
    {
33
        $this->message = "Returned $httpStatusCode";
34
        if ($data) {
35
            $this->message = $data->message;
36
            if (isset($data->logref)) {
37
                $this->message = "$data->message [logref $data->logref]";
38
            }
39
            if (isset($data->errors)) {
40
                $this->message .= "\n";
41
                foreach ($data->errors as $attribute => $error) {
42
                    $this->message .= "[$attribute]: $error\n";
43
                }
44
            }
45
        }
46
47
        $this->code    = $httpStatusCode;
48
        $this->data    = $data;
49
        $this->content = $content;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getContent(): string
56
    {
57
        return $this->content;
58
    }
59
60
    /**
61
     * @return \stdClass
62
     */
63
    public function getData(): \stdClass
64
    {
65
        return $this->data;
66
    }
67
}
68