TrelloItemNotFoundException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 75
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A getNotFoundMessage() 0 8 2
A getItemName() 0 4 1
A getItemType() 0 4 1
1
<?php
2
3
namespace TrelloBurndown\Exception;
4
5
/**
6
 * Class TrelloItemNotFoundException.
7
 */
8
class TrelloItemNotFoundException extends \Exception
9
{
10
    /**
11
     * @var array
12
     */
13
    private static $itemTypes = [
14
        'board',
15
        'list',
16
        'card',
17
    ];
18
19
    /**
20
     * @var string
21
     */
22
    private $itemType;
23
24
    /**
25
     * @var string
26
     */
27
    private $itemName;
28
29
    /**
30
     * TrelloItemNotFoundException constructor.
31
     *
32
     * @param string          $itemType
33
     * @param string          $itemName
34
     * @param int             $code
35
     * @param \Exception|null $previous
36
     */
37 7
    public function __construct(String $itemType, String $itemName, $code = 0, \Exception $previous = null)
38
    {
39 7
        $this->itemName = $itemName;
40 7
        $this->itemType = $itemType;
41
42
        try {
43 7
            $message = self::getNotFoundMessage($itemType, $itemName);
44 6
            parent::__construct($message, 404, $previous);
45 1
        } catch (\Exception $e) {
46 1
            parent::__construct($e->getMessage());
47
        }
48 7
    }
49
50
    /**
51
     * @param $itemType
52
     * @param $itemName
53
     *
54
     * @return string
55
     *
56
     * @throws \Exception
57
     */
58 7
    private static function getNotFoundMessage($itemType, $itemName)
59
    {
60 7
        if (in_array($itemType, self::$itemTypes)) {
61 6
            return 'The trello '.$itemType.' named '.$itemName.' could not be found.';
62
        }
63
64 1
        throw new \Exception('The declare Trello item type does not match any known type.');
65
    }
66
67
    /**
68
     * @return string
69
     */
70 4
    public function getItemName()
71
    {
72 4
        return $this->itemName;
73
    }
74
75
    /**
76
     * @return string
77
     */
78 4
    public function getItemType()
79
    {
80 4
        return $this->itemType;
81
    }
82
}
83