MailChimpException   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 55
rs 10
wmc 17

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 3 2
A getDetailsError() 0 13 5
A __construct() 0 5 2
A getDetail() 0 3 2
A getTypeErr() 0 3 2
A getInstance() 0 3 2
A getStatusErr() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AppBundle\Services\MailChimp;
6
7
namespace AlexCk\MailchimpBundle\Service\MailChimp;
8
9
use AlexCk\MailchimpBundle\Service\GuzzleClient\GuzzleClientException;
10
11
class MailChimpException extends GuzzleClientException
12
{
13
    /**
14
     * @var array
15
     */
16
    private $parsedContents;
17
18
    public function __construct($code, $message, $contents = '')
19
    {
20
        parent::__construct($code, $message, $contents);
21
22
        $this->parsedContents = $this->getExceptionContents() ? \GuzzleHttp\json_decode($this->getExceptionContents(), true) : '';
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getExceptionConte...nContents(), true) : '' can also be of type string. However, the property $parsedContents is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
23
    }
24
25
    public function getTypeErr(): string
26
    {
27
        return isset($this->parsedContents['type']) ? $this->parsedContents['type'] : '';
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function getTitle()
34
    {
35
        return isset($this->parsedContents['title']) ? $this->parsedContents['title'] : '';
36
    }
37
38
    public function getDetail(): string
39
    {
40
        return isset($this->parsedContents['detail']) ? $this->parsedContents['detail'] : '';
41
    }
42
43
    public function getInstance(): string
44
    {
45
        return isset($this->parsedContents['instance']) ? $this->parsedContents['instance'] : '';
46
    }
47
48
    public function getStatusErr(): string
49
    {
50
        return isset($this->parsedContents['status']) ? $this->parsedContents['status'] : '';
51
    }
52
53
    public function getDetailsError(): string
54
    {
55
        $error = $this->getTitle();
56
57
        if (isset($this->parsedContents['errors']) && count($this->parsedContents['errors']) > 0) {
58
            $error = $this->parsedContents['errors'][0];
59
60
            if (is_array($error) && isset($error['message'])) {
61
                $error = $error['message'];
62
            }
63
        }
64
65
        return $error;
66
    }
67
}
68