PivotalTrackerMessage::description()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace NotificationChannels\PivotalTracker;
4
5
use NotificationChannels\PivotalTracker\Exceptions\CouldNotCreateMessage;
6
7
class PivotalTrackerMessage
8
{
9
    /** @var string */
10
    protected $name;
11
12
    /** @var string */
13
    protected $description;
14
15
    /** @var string */
16
    protected $type = 'chore';
17
18
    /** @var array list of labels (strings list) */
19
    protected $labels = [];
20
21
    /**
22
     * @param string $name
23
     *
24
     * @return static
25
     */
26
    public static function create($name = '')
27
    {
28
        return new static($name);
29
    }
30
31
    /**
32
     * @param string $name
33
     */
34
    public function __construct($name = '')
35
    {
36
        $this->name = $name;
37
    }
38
39
    /**
40
     * Set the story name.
41
     *
42
     * @param $name
43
     *
44
     * @return $this
45
     */
46
    public function name($name)
47
    {
48
        $this->name = $name;
49
50
        return $this;
51
    }
52
53
    /**
54
     * Set the story description.
55
     *
56
     * @param $description
57
     *
58
     * @return $this
59
     */
60
    public function description($description)
61
    {
62
        $this->description = $description;
63
64
        return $this;
65
    }
66
67
    /**
68
     * Set the story type.
69
     *
70
     * @param string $type
71
     *
72
     * @return $this
73
     *
74
     * @throws CouldNotCreateMessage
75
     */
76
    public function type($type)
77
    {
78
        if (! StoryType::isValid($type)) {
79
            throw CouldNotCreateMessage::invalidStoryType($type);
80
        }
81
82
        $this->type = $type;
83
84
        return $this;
85
    }
86
87
    /**
88
     * Set the story labels.
89
     *
90
     * @param array|mixed
91
     *
92
     * @return $this
93
     *
94
     * @throws CouldNotCreateMessage
95
     */
96
    public function labels($labels)
97
    {
98
        $this->labels = is_array($labels) ? $labels : func_get_args();
99
100
        return $this;
101
    }
102
103
    /**
104
     * @return array
105
     */
106
    public function toArray()
107
    {
108
        return [
109
            'name' => $this->name,
110
            'description' => $this->description,
111
            'story_type' => $this->type,
112
            'labels' => $this->labels,
113
        ];
114
    }
115
}
116