Completed
Push — master ( 597b3a...7866ff )
by Sébastien
39s
created

TrelloItemNotFoundException::getItemType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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