Completed
Push — master ( a519d5...4800e4 )
by Vladimir
02:20
created

PulseColumnValue::createColumnType()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
rs 8.8571
cc 5
eloc 11
nc 5
nop 2
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
14
/**
15
 * The base class used for column values belonging to a specified class
16
 *
17
 * @internal
18
 * @package allejo\DaPulse\Objects
19
 * @since 0.1.0
20
 */
21
abstract class PulseColumnValue extends ApiObject
0 ignored issues
show
Coding Style introduced by
The property $board_id is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $column_id is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $pulse_id is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $column_value is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
22
{
23
    const API_PREFIX = "boards";
24
25
    /**
26
     * The ID of the parent board that this column's Pulse belongs to.
27
     *
28
     * @var int
29
     */
30
    protected $board_id;
31
32
    /**
33
     * The ID of the current column. This is a unique identifier when accessing columns through the API.
34
     *
35
     * @var string
36
     */
37
    protected $column_id;
38
39
    /**
40
     * The ID of the Pulse this column value belongs to
41
     *
42
     * @var int
43
     */
44
    protected $pulse_id;
45
46
    /**
47
     * The value that this column has. The data type can be an integer, string, or DateTime depending on the column type
48
     *
49
     * @var mixed
50
     */
51
    protected $column_value;
52
53
    /**
54
     * This constructor only accepts an array of the data regarding a specific column
55
     *
56
     * @internal
57
     *
58
     * @param array $array An associative array containing information regarding a column's value
59
     *
60
     * @since 0.1.0
61
     *
62
     * @throw \InvalidArgumentException An ID is given when an instance of this object can only be created from an array
63
     *        of existing data
64
     */
65
    public function __construct($array)
66
    {
67
        $this->arrayConstructionOnly = true;
68
69
        parent::__construct($array);
70
    }
71
72
    /**
73
     * Create the appropriate object based on the type of column
74
     *
75
     * @internal
76
     *
77
     * @param string $type The type of column as specified by DaPulse's API; i.e. 'text', 'date', 'color', 'person'
78
     * @param array  $data An associative array containing data regarding the column
79
     *
80
     * @since 0.1.0
81
     *
82
     * @throws \allejo\DaPulse\Exceptions\InvalidObjectException
83
     *
84
     * @return PulseColumnColorValue|PulseColumnDateValue|PulseColumnPersonValue|PulseColumnTextValue
85
     */
86
    public static function _createColumnType ($type, $data)
87
    {
88
        switch ($type)
89
        {
90
            case "text":
91
                return (new PulseColumnTextValue($data));
92
93
            case "color":
94
                return (new PulseColumnColorValue($data));
95
96
            case "person":
97
                return (new PulseColumnPersonValue($data));
98
99
            case "date":
100
                return (new PulseColumnDateValue($data));
101
        }
102
103
        throw new InvalidObjectException("'$type' is an unsupported column type to modify.");
104
    }
105
106
    abstract public function getValue();
107
    abstract public function updateValue($updateValue);
108
}