Test Failed
Branch master (34db35)
by Rizart
02:11
created

EmailRequest::getSubjectEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @author Rizart Dokollari <[email protected]>
4
 * @since 6/3/16
5
 */
6
7
namespace ElasticEmail\V2\Requests\Email;
8
9
use ElasticEmail\V2\Requests\BaseRequest;
10
use ElasticEmail\V2\Requests\RequestInterface;
11
use ElasticEmail\V2\Responses\Email\EmailResponse;
12
13
class EmailRequest extends BaseRequest implements RequestInterface
14
{
15
    /**
16
     * @param array $emailData to, subject, from keys required.
17
     * @return EmailResponse
18
     */
19
    public function send(array $emailData)
20
    {
21
        $this->handlerRequestValidation($emailData);
22
23
        $guzzleResponse = $this->getHttpClient()->request('POST', 'email/send', [
24
            'form_params' => array_merge($this->config, $emailData),
25
        ]);
26
27
        return new EmailResponse($guzzleResponse);
0 ignored issues
show
Compatibility introduced by
$guzzleResponse of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
28
    }
29
30
    private function handlerRequestValidation($emailData)
31
    {
32
        if (!array_key_exists('to', $emailData)) {
33
            throw new RequestException("At least one recipient must be specified. Array key: 'to'");
34
        }
35
36
        if (!filter_var($emailData['to'], FILTER_VALIDATE_EMAIL)) {
37
            throw new RequestException('Invalid recipient email.');
38
        }
39
40
        if (!array_key_exists('subject', $emailData)) {
41
            throw new RequestException('Subject field must be specified.');
42
        }
43
44
        if (!array_key_exists('from', $emailData)) {
45
            throw new RequestException('Invalid FROM email address.');
46
        }
47
48
        return true;
49
    }
50
51
    public function getRecipientEmail()
52
    {
53
        return '[email protected]';
54
    }
55
56
    public function getSenderEmail()
57
    {
58
        return '[email protected]';
59
    }
60
61
    public function getSubjectEmail()
62
    {
63
        return 'Elastic Email Subject';
64
    }
65
}
66