Completed
Push — master ( a3fc91...eb0343 )
by Vladimir
02:52
created

PulseNote   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 194
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 10
Bugs 0 Features 5
Metric Value
wmc 12
c 10
b 0
f 5
lcom 1
cbo 1
dl 0
loc 194
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getType() 0 4 1
A getId() 0 4 1
A getTitle() 0 4 1
A getProjectId() 0 4 1
A getPermissions() 0 4 1
A getContent() 0 4 1
A getCreatedAt() 0 4 1
A getUpdatedAt() 0 4 1
A editNote() 0 20 1
A deleteNote() 0 8 1
A getNotesUrl() 0 4 1
1
<?php
2
3
namespace allejo\DaPulse;
4
5
use allejo\DaPulse\Objects\ApiObject;
6
7
class PulseNote extends ApiObject
0 ignored issues
show
Coding Style introduced by
The property $project_id is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $created_at is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $updated_at is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
8
{
9
    const API_PREFIX = "pulses";
10
11
    // ================================================================================================================
12
    //   Instance Variables
13
    // ================================================================================================================
14
15
    /**
16
     * The collaboration box type (rich_text, file_list, faq_list).
17
     *
18
     * @var string
19
     */
20
    protected $type;
21
22
    /**
23
     * The note's id.
24
     *
25
     * @var string
26
     */
27
    protected $id;
28
29
    /**
30
     * The note's title.
31
     *
32
     * @var string
33
     */
34
    protected $title;
35
36
    /**
37
     * The note's project_id.
38
     *
39
     * @var string
40
     */
41
    protected $project_id;
42
43
    /**
44
     * Describes who can edit this note. Can be either 'everyone' or 'owners'.
45
     *
46
     * @var string
47
     */
48
    protected $permissions;
49
50
    /**
51
     * The note's body
52
     *
53
     * @var string
54
     */
55
    protected $content;
56
57
    /**
58
     * Creation time.
59
     *
60
     * @var \DateTime
61
     */
62
    protected $created_at;
63
64
    /**
65
     * Last update time.
66
     *
67
     * @var \DateTime
68
     */
69
    protected $updated_at;
70
71
    public function __construct ($array)
72
    {
73
        $this->arrayConstructionOnly = true;
74
75
        parent::__construct($array);
76
    }
77
78
    // ================================================================================================================
79
    //   Getter functions
80
    // ================================================================================================================
81
82
    /**
83
     * The collaboration box type (rich_text, file_list, faq_list).
84
     *
85
     * @return string
86
     */
87
    public function getType()
88
    {
89
        return $this->type;
90
    }
91
92
    /**
93
     * The note's id.
94
     *
95
     * @return string
96
     */
97
    public function getId()
98
    {
99
        return $this->id;
100
    }
101
102
    /**
103
     * The note's title.
104
     *
105
     * @return string
106
     */
107
    public function getTitle()
108
    {
109
        return $this->title;
110
    }
111
112
    /**
113
     * The note's project_id.
114
     *
115
     * @return string
116
     */
117
    public function getProjectId()
118
    {
119
        return $this->project_id;
120
    }
121
122
    /**
123
     * Describes who can edit this note. Can be either 'everyone' or 'owners'.
124
     *
125
     * @return string
126
     */
127
    public function getPermissions()
128
    {
129
        return $this->permissions;
130
    }
131
132
    /**
133
     * The note's body.
134
     *
135
     * @return string
136
     */
137
    public function getContent()
138
    {
139
        return $this->content;
140
    }
141
142
    /**
143
     * Creation time.
144
     *
145
     * @return \DateTime
146
     */
147
    public function getCreatedAt()
148
    {
149
        return $this->created_at;
150
    }
151
152
    /**
153
     * Last update time.
154
     *
155
     * @return \DateTime
156
     */
157
    public function getUpdatedAt()
158
    {
159
        return $this->updated_at;
160
    }
161
162
    // ================================================================================================================
163
    //   Modification functions
164
    // ================================================================================================================
165
166
    public function editNote ($title = NULL, $content = NULL, $user_id = NULL, $create_update = NULL)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $user_id is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Naming introduced by
The parameter $create_update is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
167
    {
168
        $this->checkInvalid();
169
170
        $url        = $this->getNotesUrl();
171
        $postParams = array(
172
            "id"      => $this->getProjectId(),
173
            "note_id" => $this->getId()
174
        );
175
176
        self::setIfNotNullOrEmpty($postParams, "title", $title);
177
        self::setIfNotNullOrEmpty($postParams, "content", $content);
178
        self::setIfNotNullOrEmpty($postParams, "user_id", $user_id);
179
        self::setIfNotNullOrEmpty($postParams, "create_update", $create_update);
180
181
        $this->jsonResponse = self::sendPut($url, $postParams);
0 ignored issues
show
Documentation Bug introduced by
It seems like self::sendPut($url, $postParams) of type * is incompatible with the declared type array of property $jsonResponse.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
182
        $this->assignResults();
183
184
        return $this;
185
    }
186
187
    public function deleteNote ()
188
    {
189
        $this->checkInvalid();
190
191
        self::sendDelete($this->getNotesUrl());
192
193
        $this->deletedObject = true;
194
    }
195
196
    private function getNotesUrl ()
197
    {
198
        return sprintf("%s/%s/notes/%s.json", self::apiEndpoint(), $this->getProjectId(), $this->getId());
199
    }
200
}