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

ApiResponseErrorException   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 54
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 20 5
A getContent() 0 4 1
A getData() 0 4 1
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