Completed
Push — develop ( f0afa6...187580 )
by Vladimir
03:00
created

PulseColumnStatusValue   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 156
ccs 15
cts 15
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 4 1
A updateValue() 0 16 4
A getHexColor() 0 18 1
A setValue() 0 8 3
1
<?php
2
3
namespace allejo\DaPulse\Objects;
4
5
/**
6
 * Class PulseColumnColorValue
7
 *
8
 * @package allejo\DaPulse\Objects
9
 * @since   0.1.0
10
 */
11
class PulseColumnStatusValue extends PulseColumnValue
12
{
13
    const DEFAULT_VALUE = self::Grey; // The default color for DaPulse columns
14
15
    /**
16
     * The index of the orange status
17
     */
18
    const Orange = 0;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected ORANGE).
Loading history...
19
20
    /**
21
     * The index of the light green status
22
     */
23
    const L_Green = 1;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected L_GREEN).
Loading history...
24
25
    /**
26
     * The index of the red status
27
     */
28
    const Red = 2;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected RED).
Loading history...
29
30
    /**
31
     * The index of the blue status
32
     */
33
    const Blue = 3;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected BLUE).
Loading history...
34
35
    /**
36
     * The index of the purple status
37
     */
38
    const Purple = 4;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected PURPLE).
Loading history...
39
40
    /**
41
     * The index of the grey status
42
     */
43
    const Grey = 5;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected GREY).
Loading history...
44
    const Gray = self::Grey; // just an alias
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected GRAY).
Loading history...
45
46
    /**
47
     * The index of the green status
48
     */
49
    const Green = 6;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected GREEN).
Loading history...
50
51
    /**
52
     * The index of the light blue status
53
     */
54
    const L_Blue = 7;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected L_BLUE).
Loading history...
55
56
    /**
57
     * The index of the gold status
58
     */
59
    const Gold = 8;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected GOLD).
Loading history...
60
61
    /**
62
     * The index of the yellow status
63
     */
64
    const Yellow = 9;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected YELLOW).
Loading history...
65
66
    /**
67
     * The index of the black status
68
     */
69
    const Black = 10;
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected BLACK).
Loading history...
70
71
    /**
72
     * Get the numerical representation of the color that a status column is set to.
73
     *
74
     * @api
75
     *
76
     * @since  0.1.0
77
     *
78
     * @return int The color value of a column
79
     */
80 2
    public function getValue ()
81
    {
82 2
        return parent::getValue();
83
    }
84
85
    /**
86
     * Update the status of a status column
87
     *
88
     * It is highly recommended that you use the constants available in the **PulseColumnColorValue** class to match the
89
     * colors; keep in mind this value cannot be higher than 11.
90
     *
91
     * @api
92
     *
93
     * @param int $color The numerical value of the new color value
94
     *
95
     * @see   PulseColumnStatusValue::Orange  PulseColumnStatusValue::Orange
96
     * @see   PulseColumnStatusValue::L_Green PulseColumnStatusValue::L_Green
97
     * @see   PulseColumnStatusValue::Red     PulseColumnStatusValue::Red
98
     * @see   PulseColumnStatusValue::Blue    PulseColumnStatusValue::Blue
99
     * @see   PulseColumnStatusValue::Purple  PulseColumnStatusValue::Purple
100
     * @see   PulseColumnStatusValue::Grey    PulseColumnStatusValue::Grey
101
     * @see   PulseColumnStatusValue::Green   PulseColumnStatusValue::Green
102
     * @see   PulseColumnStatusValue::L_Blue  PulseColumnStatusValue::L_Blue
103
     * @see   PulseColumnStatusValue::Gold    PulseColumnStatusValue::Gold
104
     * @see   PulseColumnStatusValue::Yellow  PulseColumnStatusValue::Yellow
105
     * @see   PulseColumnStatusValue::Black   PulseColumnStatusValue::Black
106
     *
107
     * @since 0.1.0
108
     *
109
     * @throws \InvalidArgumentException if the $color is not an int or is not between 0-10
110
     */
111 5
    public function updateValue ($color)
112
    {
113 5
        if ($color < 0 || $color > 10 || !is_int($color))
114
        {
115 4
            throw new \InvalidArgumentException("DaPulse only has color indexes from 0-10");
116
        }
117
118 1
        $url        = sprintf("%s/%d/columns/%s/status.json", self::apiEndpoint(), $this->board_id, $this->column_id);
119
        $postParams = array(
120 1
            "pulse_id"    => $this->pulse_id,
121 1
            "color_index" => $color
122
        );
123
124 1
        $result = self::sendPut($url, $postParams);
125 1
        $this->setValue($result);
126 1
    }
127
128
    /**
129
     * Get the hex value of the color used on DaPulse to represent the different statuses.
130
     *
131
     * @api
132
     *
133
     * @param  int $numericalValue The numerical value of the column
134
     *
135
     * @since  0.1.0
136
     *
137
     * @return string A hex value **without** the leading #
138
     */
139
    public static function getHexColor ($numericalValue)
140
    {
141
        $colorArray = array(
142
            self::Orange  => "fdab3d",
143
            self::L_Green => "00c875",
144
            self::Red     => "e2445c",
145
            self::Blue    => "0086c0",
146
            self::L_Blue  => "579bfc",
147
            self::Purple  => "a25ddc",
148
            self::Green   => "037f4c",
149
            self::Gold    => "CAB641",
150
            self::Yellow  => "FFCB00",
151
            self::Black   => "333333",
152
            self::Grey    => "c4c4c4"
153
        );
154
155
        return $colorArray[$numericalValue];
156
    }
157
158 2
    protected function setValue ($response)
159
    {
160 2
        $value = $response['value'];
161
162
        // If the status column is set to 'Grey' or the default 'Just Assigned' value, DaPulse will evidently
163
        // return null... So let's set it to the Grey value to not confuse people
164 2
        $this->column_value = (is_array($value) && array_key_exists('index', $value)) ? $response["value"]["index"] : self::Grey;
165
    }
166
}