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

PulseColumnTimelineValue   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 14
loc 70
ccs 20
cts 20
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 14 14 3
A updateValue() 0 17 3
A setValue() 0 7 1

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.2.1
10
 */
11
class PulseColumnTimelineValue extends PulseColumnValue
12
{
13
    /**
14
     * Get a timeline column's content
15
     *
16
     * @api
17
     *
18
     * @since  0.2.1
19
     *
20
     * @return \DateTime[]|null The timeline's begin and end dates
21
     *
22
     *     array(
23
     *       'from' => \DateTime
24
     *       'to'   => \DateTime
25
     *     )
26
     */
27 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...
28
    {
29 3
        if ($this->isNullValue())
30
        {
31 1
            return null;
32
        }
33
34 2
        if (!isset($this->column_value))
35
        {
36 1
            $this->setValue($this->jsonResponse);
37
        }
38
39 2
        return $this->column_value;
40
    }
41
42
    /**
43
     * Update the values of a timeline column
44
     *
45
     * @api
46
     *
47
     * @param \DateTime $from
48
     * @param \DateTime $to
49
     *
50
     * @since 0.3.0 \InvalidArgumentException is now thrown
51
     * @since 0.2.1
52
     *
53
     * @throws \InvalidArgumentException if $from or $to are not \DateTime instances
54
     */
55 1
    public function updateValue ($from, $to)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $to. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
56
    {
57 1
        if (!($from instanceof \DateTime) || !($to instanceof \DateTime))
58
        {
59
            throw new \InvalidArgumentException('$from and $to are expected to be \\DateTime instances');
60
        }
61
62 1
        $url        = sprintf("%s/%d/columns/%s/timeline.json", self::apiEndpoint(), $this->board_id, $this->column_id);
63
        $postParams = [
64 1
            "pulse_id" => $this->pulse_id,
65 1
            "from"     => $from->format('Y-m-d'),
66 1
            "to"       => $to->format('Y-m-d')
67
        ];
68
69 1
        $result = self::sendPut($url, $postParams);
70 1
        $this->setValue($result);
71 1
    }
72
73 2
    protected function setValue ($response)
74
    {
75 2
        $this->column_value = [
76 2
            'from' => new \DateTime($response["value"]["from"]),
77 2
            'to'   => new \DateTime($response["value"]["to"])
78
        ];
79
    }
80
}