Task   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 25
dl 0
loc 95
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setCompleteTill() 0 5 1
A setIsComplete() 0 4 1
A loadInRaw() 0 6 1
A isIsComplete() 0 3 1
A __construct() 0 8 2
A getCompleteTill() 0 3 1
A getExtraRaw() 0 9 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: DrillCoder
5
 * Date: 26.09.17
6
 * Time: 14:31
7
 */
8
9
namespace DrillCoder\AmoCRM_Wrap;
10
11
use DateTime;
12
use Exception;
13
use stdClass;
14
15
/**
16
 * Class Task
17
 * @package DrillCoder\AmoCRM_Wrap
18
 */
19
class Task extends BaseEntity
20
{
21
    /**
22
     * @var bool
23
     */
24
    private $isComplete;
25
26
    /**
27
     * @var DateTime
28
     */
29
    private $completeTill;
30
31
    /**
32
     * Task constructor.
33
     *
34
     * @param null $id
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $id is correct as it would always require null to be passed?
Loading history...
35
     *
36
     * @throws AmoWrapException
37
     */
38
    public function __construct($id = null)
39
    {
40
        parent::__construct($id);
41
42
        try {
43
            $this->completeTill = new DateTime();
44
        } catch (Exception $e) {
45
            throw new AmoWrapException("Ошибка в обёртке: {$e->getMessage()}", $e->getCode(), $e);
46
        }
47
    }
48
49
    /**
50
     * @param stdClass $data
51
     *
52
     * @return Task
53
     * @throws AmoWrapException
54
     */
55
    public function loadInRaw($data)
56
    {
57
        BaseEntity::loadInRaw($data);
58
        $this->isComplete = $data->is_completed;
59
        $this->completeTill->setTimestamp($data->complete_till_at);
60
        return $this;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function isIsComplete()
67
    {
68
        return $this->isComplete;
69
    }
70
71
    /**
72
     * @param bool $isComplete
73
     *
74
     * @return Task
75
     */
76
    public function setIsComplete($isComplete)
77
    {
78
        $this->isComplete = $isComplete;
79
        return $this;
80
    }
81
82
    /**
83
     * @return DateTime
84
     */
85
    public function getCompleteTill()
86
    {
87
        return $this->completeTill;
88
    }
89
90
    /**
91
     * @param DateTime $completeTill
92
     *
93
     * @return Task
94
     */
95
    public function setCompleteTill(DateTime $completeTill)
96
    {
97
        $this->completeTill = $completeTill;
98
99
        return $this;
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    protected function getExtraRaw()
106
    {
107
        return array(
108
            'complete_till_at' => $this->completeTill->format('U'),
109
            'is_completed' => $this->isComplete,
110
            'element_id' => $this->elementId,
111
            'element_type' => $this->elementType,
112
            'task_type' => $this->type,
113
            'text' => $this->text,
114
        );
115
    }
116
}