Code Duplication    Length = 26-27 lines in 3 locations

src/Charcoal/Email/Email.php 3 locations

@@ 221-246 (lines=26) @@
218
     * @throws InvalidArgumentException If the email address is invalid.
219
     * @return self
220
     */
221
    public function setTo($email)
222
    {
223
        if (is_string($email)) {
224
            $email = [ $email ];
225
        }
226
227
        if (!is_array($email)) {
228
            throw new InvalidArgumentException(
229
                'Must be an array of recipients.'
230
            );
231
        }
232
233
        $this->to = [];
234
235
        // At this point, `$email` can be an _email array_ or an _array of emails_...
236
        if (isset($email['email'])) {
237
            // Means we're not dealing with multiple emails
238
            $this->addTo($email);
239
        } else {
240
            foreach ($email as $recipient) {
241
                $this->addTo($recipient);
242
            }
243
        }
244
245
        return $this;
246
    }
247
248
    /**
249
     * Add a recipient email address.
@@ 278-303 (lines=26) @@
275
     * @throws InvalidArgumentException If the email address is invalid.
276
     * @return self
277
     */
278
    public function setCc($email)
279
    {
280
        if (is_string($email)) {
281
            $email = [ $email ];
282
        }
283
284
        if (!is_array($email)) {
285
            throw new InvalidArgumentException(
286
                'Must be an array of CC recipients.'
287
            );
288
        }
289
290
        $this->cc = [];
291
292
        // At this point, `$email` can be an _email array_ or an _array of emails_...
293
        if (isset($email['email'])) {
294
            // Means we're not dealing with multiple emails
295
            $this->addCc($email);
296
        } else {
297
            foreach ($email as $recipient) {
298
                $this->addCc($recipient);
299
            }
300
        }
301
302
        return $this;
303
    }
304
305
    /**
306
     * Add a CC recipient email address.
@@ 335-361 (lines=27) @@
332
     * @throws InvalidArgumentException If the email address is invalid.
333
     * @return self
334
     */
335
    public function setBcc($email)
336
    {
337
        if (is_string($email)) {
338
            // Means we have a straight email
339
            $email = [ $email ];
340
        }
341
342
        if (!is_array($email)) {
343
            throw new InvalidArgumentException(
344
                'Must be an array of BCC recipients.'
345
            );
346
        }
347
348
        $this->bcc = [];
349
350
        // At this point, `$email` can be an _email array_ or an _array of emails_...
351
        if (isset($email['email'])) {
352
            // Means we're not dealing with multiple emails
353
            $this->addBcc($email);
354
        } else {
355
            foreach ($email as $recipient) {
356
                $this->addBcc($recipient);
357
            }
358
        }
359
360
        return $this;
361
    }
362
363
    /**
364
     * Add a BCC recipient email address.