Completed
Push — develop ( f0afa6...187580 )
by Vladimir
03:00
created

PulseColumnDateValue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 26.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 16
loc 60
ccs 17
cts 17
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 4 1
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
    public function getValue ()
23
    {
24 3
        return parent::getValue();
25
    }
26
27
    /**
28
     * Update the date of the date column.
29
     *
30
     * The specific time of the DateTime object will be ignored.
31
     *
32
     * @api
33
     *
34
     * @param \DateTime $dateTime The new date
35
     *
36
     * @since 0.3.0 \InvalidArgumentException is now thrown
37
     * @since 0.1.0
38
     *
39
     * @throws \InvalidArgumentException if $dateTime is not a \DateTime
40
     */
41 5 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...
42
    {
43 5
        if (!($dateTime instanceof \DateTime))
44
        {
45 4
            throw new \InvalidArgumentException('$dateTime is expected to be of type \\DateTime');
46
        }
47
48 1
        $url        = sprintf("%s/%d/columns/%s/date.json", self::apiEndpoint(), $this->board_id, $this->column_id);
49
        $postParams = array(
50 1
            "pulse_id" => $this->pulse_id,
51 1
            "date_str" => date_format($dateTime, "Y-m-d")
52
        );
53
54 1
        $result = self::sendPut($url, $postParams);
55 1
        $this->setValue($result);
56 1
    }
57
58 2
    protected function setValue ($response)
59
    {
60
        // Another DaPulse API inconsistency. The data returned from a PUT request has the date in an array instead of
61
        // of a string.
62 2
        if (is_array($response['value']) && isset($response['value']['date']))
63
        {
64 1
            $this->column_value = new \DateTime($response['value']['date']);
65 1
            return;
66
        }
67
68 1
        $this->column_value = new \DateTime($response['value']);
69
    }
70
}