Completed
Push — master ( 4a1992...3a4f99 )
by Vladimir
06:33
created

PulseColumn::getBoardId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\DaPulse;
9
10
use allejo\DaPulse\Exceptions\InvalidColumnException;
11
use allejo\DaPulse\Objects\ApiObject;
12
use allejo\DaPulse\Objects\PulseColumnStatusValue as StatusColumn;
13
14
/**
15
 * Class PulseColumn
16
 *
17
 * @api
18
 * @package allejo\DaPulse
19
 * @since   0.1.0
20
 */
21
class PulseColumn extends ApiObject
22
{
23
    const API_PREFIX = "boards";
24
25
    const Date     = "date";
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected DATE).
Loading history...
26
    const Numeric  = "numeric";
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected NUMERIC).
Loading history...
27
    const Person   = "person";
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected PERSON).
Loading history...
28
    const Status   = "status";
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected STATUS).
Loading history...
29
    const Text     = "text";
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected TEXT).
Loading history...
30
    const Timeline = "timerange";
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected TIMELINE).
Loading history...
31
32
    protected $title;
33
    protected $type;
34
    protected $empty_text;
35
    protected $labels;
36
    protected $board_id;
37
38
    private $labelsSanityCheck;
39
40
    /**
41
     * PulseColumn constructor.
42
     *
43
     * @internal
44
     *
45
     * @param array $idOrArray
46
     */
47 40
    public function __construct ($idOrArray)
48
    {
49 40
        $this->arrayConstructionOnly = true;
50 40
        $this->labelsSanityCheck = false;
51
52 40
        parent::__construct($idOrArray);
53 40
    }
54
55
    public function getId ()
56
    {
57
        return $this->id;
58
    }
59
60
    public function getTitle ()
61
    {
62
        $this->lazyLoad();
63
64
        return $this->title;
65
    }
66
67 13
    public function getType ()
68
    {
69 13
        $this->lazyLoad();
70
71
        // @todo Workaround due to a bug in DaPulse's API see: https://github.com/allejo/PhpPulse/issues/5
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
72 13
        if ($this->type === "color")
73 13
        {
74 2
            $this->type = self::Status;
75 2
        }
76
77 13
        return $this->type;
78
    }
79
80
    /**
81
     * Get the labels for a Status column type
82
     *
83
     * @throws InvalidColumnException if the column is not a Status column
84
     *
85
     * @since  0.3.0 An InvalidColumnException is thrown when the given column is not a status column
86
     * @since  0.1.0
87
     *
88
     * @return string[]
89
     */
90 2
    public function getLabels ()
91
    {
92 2
        if ($this->getType() != PulseColumn::Status)
93 2
        {
94 1
            throw new InvalidColumnException('This column type does not contain labels');
95
        }
96
97 1
        $this->lazyLoad();
98 1
        $this->sanitizeLabels();
99
100 1
        return $this->labels;
101
    }
102
103
    public function getBoardId ()
104
    {
105
        $this->lazyLoad();
106
107
        return $this->board_id;
108
    }
109
110
    public function editTitle ($title)
111
    {
112
        $this->editField("title", $title);
113
    }
114
115
    public function editLabels ($labels)
116
    {
117
        $this->editField("labels", $labels);
118
    }
119
120
    public function deleteColumn ()
121
    {
122
        $this->checkInvalid();
123
124
        self::sendDelete($this->getColumnsUrl());
125
126
        $this->deletedObject = true;
127
    }
128
129
    private function editField ($field, $value)
130
    {
131
        $this->checkInvalid();
132
133
        $postParams = [
134
            $field => $value
135
        ];
136
137
        self::sendPut($this->getColumnsUrl(), $postParams);
138
139
        $this->$field = $value;
140
    }
141
142
    private function getColumnsUrl ()
143
    {
144
        return sprintf("%s/%d/columns/%s.json", parent::apiEndpoint(), $this->getBoardId(), $this->getId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (apiEndpoint() instead of getColumnsUrl()). Are you sure this is correct? If so, you might want to change this to $this->apiEndpoint().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
145
    }
146
147
    /**
148
     * DaPulse will only set labels if it has content
149
     */
150 1
    private function sanitizeLabels ()
151
    {
152 1
        if ($this->labelsSanityCheck)
153 1
        {
154
            return;
155
        }
156
157 1
        for ($i = StatusColumn::MIN_VALUE; $i <= StatusColumn::MAX_VALUE; $i++)
158
        {
159 1
            !isset($this->labels[$i]) && $this->labels[$i] = '';
160 1
        }
161
162 1
        $this->labelsSanityCheck = true;
163
    }
164
}