Issues (219)

Branch: 4-cactus

BEdita/Core/src/Job/Service/MailService.php (1 issue)

1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2017 ChannelWeb Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
14
namespace BEdita\Core\Job\Service;
15
16
use BEdita\Core\Job\JobService;
17
use BEdita\Core\Mailer\Email;
18
use Cake\Utility\Hash;
19
20
/**
21
 * Service to send single mail
22
 *
23
 * @since 4.0.0
24
 */
25
class MailService implements JobService
26
{
27
    /**
28
     * Send a single email.
29
     *
30
     * Payload **MUST** contain a set of options compatible with {@see \Cake\Mailer\Email::createFromArray()}.
31
     *
32
     * Options can contain the following keys:
33
     *  - `transport`: mail transport to use (default: `'default'`).
34
     *
35
     * @param array $payload Input data for this email job.
36
     * @param array $options Options for running this job.
37
     * @return array Result from {@see \Cake\Mailer\Email::send()}.
38
     */
39
    public function run(array $payload, array $options = [])
40
    {
41
        $transport = Hash::get($options, 'transport', 'default');
42
43
        $email = (new Email())
44
            ->createFromArray($payload)
45
            ->setTransport($transport);
46
47
        return $email->sendRaw();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $email->sendRaw() returns the type array which is incompatible with the return type mandated by BEdita\Core\Job\JobService::run() of boolean.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
48
    }
49
}
50