Completed
Push — develop ( a05ff5...d1fb89 )
by Vladimir
03:27
created

PulseColumnDateValue   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 42.86 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 1
dl 30
loc 70
ccs 20
cts 20
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 14 14 3
A updateValue() 16 16 2
A setValue() 0 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace allejo\DaPulse\Objects;
4
5
/**
6
 * Class PulseColumnTextValue
7
 *
8
 * @package allejo\DaPulse\Objects
9
 * @since   0.1.0
10
 */
11
class PulseColumnDateValue extends PulseColumnValue
12
{
13
    /**
14
     * Get the date listed in the date column
15
     *
16
     * @api
17
     *
18
     * @since  0.1.0
19
     *
20
     * @return \DateTime|null Null is returned if there is no value set for this column
21
     */
22 3 View Code Duplication
    public function getValue ()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24 3
        if ($this->isNullValue())
25
        {
26 2
            return null;
27
        }
28
29 2
        if (!isset($this->column_value))
30
        {
31 1
            $this->setValue($this->jsonResponse);
32
        }
33
34 2
        return $this->column_value;
35
    }
36
37
    /**
38
     * Update the date of the date column.
39
     *
40
     * The specific time of the DateTime object will be ignored.
41
     *
42
     * @api
43
     *
44
     * @param \DateTime $dateTime The new date
45
     *
46
     * @since 0.3.0 \InvalidArgumentException is now thrown
47
     * @since 0.1.0
48
     *
49
     * @throws \InvalidArgumentException if $dateTime is not a \DateTime
50
     */
51 1 View Code Duplication
    public function updateValue ($dateTime)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53 1
        if (!($dateTime instanceof \DateTime))
54
        {
55
            throw new \InvalidArgumentException('$dateTime is expected to be of type \\DateTime');
56
        }
57
58 1
        $url        = sprintf("%s/%d/columns/%s/date.json", self::apiEndpoint(), $this->board_id, $this->column_id);
59
        $postParams = array(
60 1
            "pulse_id" => $this->pulse_id,
61 1
            "date_str" => date_format($dateTime, "Y-m-d")
62
        );
63
64 1
        $result = self::sendPut($url, $postParams);
65 1
        $this->setValue($result);
66 1
    }
67
68 2
    protected function setValue ($response)
69
    {
70
        // Another DaPulse API inconsistency. The data returned from a PUT request has the date in an array instead of
71
        // of a string.
72 2
        if (is_array($response['value']) && isset($response['value']['date']))
73
        {
74 1
            $this->column_value = new \DateTime($response['value']['date']);
75 1
            return;
76
        }
77
78 1
        $this->column_value = new \DateTime($response['value']);
79
    }
80
}