Completed
Push — master ( 5ff3fc...6d5399 )
by Vladimir
02:24
created

PulseColumnValue::isNullValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * This file contains the PulseColumnValue class
5
 *
6
 * @copyright 2015 Vladimir Jimenez
7
 * @license   https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT
8
 */
9
10
namespace allejo\DaPulse\Objects;
11
12
use allejo\DaPulse\Exceptions\InvalidObjectException;
13
use allejo\DaPulse\PulseColumn;
14
15
/**
16
 * The base class used for column values belonging to a specified class
17
 *
18
 * @internal
19
 * @package allejo\DaPulse\Objects
20
 * @since   0.1.0
21
 */
22
abstract class PulseColumnValue extends ApiObject
23
{
24
    const API_PREFIX = "boards";
25
26
    /**
27
     * The ID of the parent board that this column's Pulse belongs to.
28
     *
29
     * @var int
30
     */
31
    protected $board_id;
32
33
    /**
34
     * The ID of the current column. This is a unique identifier when accessing columns through the API.
35
     *
36
     * @var string
37
     */
38
    protected $column_id;
39
40
    /**
41
     * The ID of the Pulse this column value belongs to
42
     *
43
     * @var int
44
     */
45
    protected $pulse_id;
46
47
    /**
48
     * The value that this column has. The data type can be an integer, string, or DateTime depending on the column type
49
     *
50
     * @var mixed
51
     */
52
    protected $column_value;
53
54
    /**
55
     * This constructor only accepts an array of the data regarding a specific column
56
     *
57
     * @internal
58
     *
59
     * @param array $array An associative array containing information regarding a column's value
60
     *
61
     * @since 0.1.0
62
     *
63
     * @throws \InvalidArgumentException An ID is given when an instance of this object can only be created from an
64
     *                                   array of existing data
65
     */
66
    public function __construct ($array)
67
    {
68
        $this->arrayConstructionOnly = true;
69
70
        parent::__construct($array);
71
    }
72
73
    /**
74
     * Create the appropriate object based on the type of column
75
     *
76
     * @internal
77
     *
78
     * @param string $type The type of column as specified by DaPulse's API; i.e. 'text', 'date', 'status', 'person'
79
     * @param array  $data An associative array containing data regarding the column
80
     *
81
     * @since 0.1.0
82
     *
83
     * @todo  Fix the hardcoded "color" case statement. See: https://github.com/allejo/PhpPulse/issues/5
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
84
     *
85
     * @throws InvalidObjectException
86
     *
87
     * @return PulseColumnStatusValue|PulseColumnDateValue|PulseColumnPersonValue|PulseColumnTextValue
88
     */
89
    public static function _createColumnType ($type, $data)
90
    {
91
        switch ($type)
92
        {
93
            case PulseColumn::Text:
94
                return (new PulseColumnTextValue($data));
95
96
            case "color":
97
            case PulseColumn::Status:
98
                return (new PulseColumnStatusValue($data));
99
100
            case PulseColumn::Person:
101
                return (new PulseColumnPersonValue($data));
102
103
            case PulseColumn::Date:
104
                return (new PulseColumnDateValue($data));
105
        }
106
107
        throw new InvalidObjectException("'$type' is an unsupported column type to modify.");
108
    }
109
110
    protected function isNullValue ()
111
    {
112
        return (is_null($this->jsonResponse["value"]) && !isset($this->column_value));
113
    }
114
115
    abstract public function getValue ();
116
117
    abstract public function updateValue ($updateValue);
118
}