Mandrill_Templates::add()   A
last analyzed

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