Passed
Push — master ( d156dd...acd975 )
by Thomas
04:20 queued 01:05
created

Mandrill_Templates::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 8
dl 0
loc 4
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
class Mandrill_Templates
4
{
5
6
    public function __construct(Mandrill $master)
7
    {
8
        $this->master = $master;
0 ignored issues
show
Bug Best Practice introduced by
The property master does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
9
    }
10
11
    /**
12
     * Add a new template
13
     * @param string $name the name for the new template - must be unique
14
     * @param string $from_email a default sending address for emails sent using this template
15
     * @param string $from_name a default from name to be used
16
     * @param string $subject a default subject line to be used
17
     * @param string $code the HTML code for the template with mc:edit attributes for the editable elements
18
     * @param string $text a default text part to be used when sending with this template
19
     * @param boolean $publish set to false to add a draft template without publishing
20
     * @param array $labels an optional array of up to 10 labels to use for filtering templates
21
     *     - labels[] string a single label
22
     * @return struct the information saved about the new template
0 ignored issues
show
Bug introduced by
The type struct was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
     *     - slug string the immutable unique code name of the template
24
     *     - name string the name of the template
25
     *     - labels array the list of labels applied to the template
26
     *         - labels[] string a single label
27
     *     - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
28
     *     - subject string the subject line of the template, if provided - draft version
29
     *     - from_email string the default sender address for the template, if provided - draft version
30
     *     - from_name string the default sender from name for the template, if provided - draft version
31
     *     - text string the default text part of messages sent with the template, if provided - draft version
32
     *     - publish_name string the same as the template name - kept as a separate field for backwards compatibility
33
     *     - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
34
     *     - publish_subject string the subject line of the template, if provided
35
     *     - publish_from_email string the default sender address for the template, if provided
36
     *     - publish_from_name string the default sender from name for the template, if provided
37
     *     - publish_text string the default text part of messages sent with the template, if provided
38
     *     - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
39
     *     - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
40
     *     - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
41
     */
42
    public function add($name, $from_email = null, $from_name = null, $subject = null, $code = null, $text = null, $publish = true, $labels = array())
43
    {
44
        $_params = array("name" => $name, "from_email" => $from_email, "from_name" => $from_name, "subject" => $subject, "code" => $code, "text" => $text, "publish" => $publish, "labels" => $labels);
45
        return $this->master->call('templates/add', $_params);
46
    }
47
48
    /**
49
     * Get the information for an existing template
50
     * @param string $name the immutable name of an existing template
51
     * @return struct the requested template information
52
     *     - slug string the immutable unique code name of the template
53
     *     - name string the name of the template
54
     *     - labels array the list of labels applied to the template
55
     *         - labels[] string a single label
56
     *     - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
57
     *     - subject string the subject line of the template, if provided - draft version
58
     *     - from_email string the default sender address for the template, if provided - draft version
59
     *     - from_name string the default sender from name for the template, if provided - draft version
60
     *     - text string the default text part of messages sent with the template, if provided - draft version
61
     *     - publish_name string the same as the template name - kept as a separate field for backwards compatibility
62
     *     - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
63
     *     - publish_subject string the subject line of the template, if provided
64
     *     - publish_from_email string the default sender address for the template, if provided
65
     *     - publish_from_name string the default sender from name for the template, if provided
66
     *     - publish_text string the default text part of messages sent with the template, if provided
67
     *     - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
68
     *     - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
69
     *     - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
70
     */
71
    public function info($name)
72
    {
73
        $_params = array("name" => $name);
74
        return $this->master->call('templates/info', $_params);
75
    }
76
77
    /**
78
     * Update the code for an existing template. If null is provided for any fields, the values will remain unchanged.
79
     * @param string $name the immutable name of an existing template
80
     * @param string $from_email the new default sending address
81
     * @param string $from_name the new default from name
82
     * @param string $subject the new default subject line
83
     * @param string $code the new code for the template
84
     * @param string $text the new default text part to be used
85
     * @param boolean $publish set to false to update the draft version of the template without publishing
86
     * @param array $labels an optional array of up to 10 labels to use for filtering templates
87
     *     - labels[] string a single label
88
     * @return struct the template that was updated
89
     *     - slug string the immutable unique code name of the template
90
     *     - name string the name of the template
91
     *     - labels array the list of labels applied to the template
92
     *         - labels[] string a single label
93
     *     - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
94
     *     - subject string the subject line of the template, if provided - draft version
95
     *     - from_email string the default sender address for the template, if provided - draft version
96
     *     - from_name string the default sender from name for the template, if provided - draft version
97
     *     - text string the default text part of messages sent with the template, if provided - draft version
98
     *     - publish_name string the same as the template name - kept as a separate field for backwards compatibility
99
     *     - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
100
     *     - publish_subject string the subject line of the template, if provided
101
     *     - publish_from_email string the default sender address for the template, if provided
102
     *     - publish_from_name string the default sender from name for the template, if provided
103
     *     - publish_text string the default text part of messages sent with the template, if provided
104
     *     - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
105
     *     - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
106
     *     - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
107
     */
108
    public function update($name, $from_email = null, $from_name = null, $subject = null, $code = null, $text = null, $publish = true, $labels = null)
109
    {
110
        $_params = array("name" => $name, "from_email" => $from_email, "from_name" => $from_name, "subject" => $subject, "code" => $code, "text" => $text, "publish" => $publish, "labels" => $labels);
111
        return $this->master->call('templates/update', $_params);
112
    }
113
114
    /**
115
     * Publish the content for the template. Any new messages sent using this template will start using the content that was previously in draft.
116
     * @param string $name the immutable name of an existing template
117
     * @return struct the template that was published
118
     *     - slug string the immutable unique code name of the template
119
     *     - name string the name of the template
120
     *     - labels array the list of labels applied to the template
121
     *         - labels[] string a single label
122
     *     - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
123
     *     - subject string the subject line of the template, if provided - draft version
124
     *     - from_email string the default sender address for the template, if provided - draft version
125
     *     - from_name string the default sender from name for the template, if provided - draft version
126
     *     - text string the default text part of messages sent with the template, if provided - draft version
127
     *     - publish_name string the same as the template name - kept as a separate field for backwards compatibility
128
     *     - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
129
     *     - publish_subject string the subject line of the template, if provided
130
     *     - publish_from_email string the default sender address for the template, if provided
131
     *     - publish_from_name string the default sender from name for the template, if provided
132
     *     - publish_text string the default text part of messages sent with the template, if provided
133
     *     - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
134
     *     - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
135
     *     - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
136
     */
137
    public function publish($name)
138
    {
139
        $_params = array("name" => $name);
140
        return $this->master->call('templates/publish', $_params);
141
    }
142
143
    /**
144
     * Delete a template
145
     * @param string $name the immutable name of an existing template
146
     * @return struct the template that was deleted
147
     *     - slug string the immutable unique code name of the template
148
     *     - name string the name of the template
149
     *     - labels array the list of labels applied to the template
150
     *         - labels[] string a single label
151
     *     - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
152
     *     - subject string the subject line of the template, if provided - draft version
153
     *     - from_email string the default sender address for the template, if provided - draft version
154
     *     - from_name string the default sender from name for the template, if provided - draft version
155
     *     - text string the default text part of messages sent with the template, if provided - draft version
156
     *     - publish_name string the same as the template name - kept as a separate field for backwards compatibility
157
     *     - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
158
     *     - publish_subject string the subject line of the template, if provided
159
     *     - publish_from_email string the default sender address for the template, if provided
160
     *     - publish_from_name string the default sender from name for the template, if provided
161
     *     - publish_text string the default text part of messages sent with the template, if provided
162
     *     - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
163
     *     - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
164
     *     - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
165
     */
166
    public function delete($name)
167
    {
168
        $_params = array("name" => $name);
169
        return $this->master->call('templates/delete', $_params);
170
    }
171
172
    /**
173
     * Return a list of all the templates available to this user
174
     * @param string $label an optional label to filter the templates
175
     * @return array an array of structs with information about each template
176
     *     - return[] struct the information on each template in the account
177
     *         - slug string the immutable unique code name of the template
178
     *         - name string the name of the template
179
     *         - labels array the list of labels applied to the template
180
     *             - labels[] string a single label
181
     *         - code string the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
182
     *         - subject string the subject line of the template, if provided - draft version
183
     *         - from_email string the default sender address for the template, if provided - draft version
184
     *         - from_name string the default sender from name for the template, if provided - draft version
185
     *         - text string the default text part of messages sent with the template, if provided - draft version
186
     *         - publish_name string the same as the template name - kept as a separate field for backwards compatibility
187
     *         - publish_code string the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
188
     *         - publish_subject string the subject line of the template, if provided
189
     *         - publish_from_email string the default sender address for the template, if provided
190
     *         - publish_from_name string the default sender from name for the template, if provided
191
     *         - publish_text string the default text part of messages sent with the template, if provided
192
     *         - published_at string the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
193
     *         - created_at string the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
194
     *         - updated_at string the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
195
     */
196
    public function getList($label = null)
197
    {
198
        $_params = array("label" => $label);
199
        return $this->master->call('templates/list', $_params);
200
    }
201
202
    /**
203
     * Return the recent history (hourly stats for the last 30 days) for a template
204
     * @param string $name the name of an existing template
205
     * @return array the array of history information
206
     *     - return[] struct the stats for a single hour
207
     *         - time string the hour as a UTC date string in YYYY-MM-DD HH:MM:SS format
208
     *         - sent integer the number of emails that were sent during the hour
209
     *         - hard_bounces integer the number of emails that hard bounced during the hour
210
     *         - soft_bounces integer the number of emails that soft bounced during the hour
211
     *         - rejects integer the number of emails that were rejected during the hour
212
     *         - complaints integer the number of spam complaints received during the hour
213
     *         - opens integer the number of emails opened during the hour
214
     *         - unique_opens integer the number of unique opens generated by messages sent during the hour
215
     *         - clicks integer the number of tracked URLs clicked during the hour
216
     *         - unique_clicks integer the number of unique clicks generated by messages sent during the hour
217
     */
218
    public function timeSeries($name)
219
    {
220
        $_params = array("name" => $name);
221
        return $this->master->call('templates/time-series', $_params);
222
    }
223
224
    /**
225
     * Inject content and optionally merge fields into a template, returning the HTML that results
226
     * @param string $template_name the immutable name of a template that exists in the user's account
227
     * @param array $template_content an array of template content to render.  Each item in the array should be a struct with two keys - name: the name of the content block to set the content for, and content: the actual content to put into the block
228
     *     - template_content[] struct the injection of a single piece of content into a single editable region
229
     *         - name string the name of the mc:edit editable region to inject into
230
     *         - content string the content to inject
231
     * @param array $merge_vars optional merge variables to use for injecting merge field content.  If this is not provided, no merge fields will be replaced.
232
     *     - merge_vars[] struct a single merge variable
233
     *         - name string the merge variable's name. Merge variable names are case-insensitive and may not start with _
234
     *         - content string the merge variable's content
235
     * @return struct the result of rendering the given template with the content and merge field values injected
236
     *     - html string the rendered HTML as a string
237
     */
238
    public function render($template_name, $template_content, $merge_vars = null)
239
    {
240
        $_params = array("template_name" => $template_name, "template_content" => $template_content, "merge_vars" => $merge_vars);
241
        return $this->master->call('templates/render', $_params);
242
    }
243
}
244