SpamTestHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 38
ccs 12
cts 14
cp 0.8571
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getApiEndpoint() 0 3 1
A spamCheck() 0 19 3
1
<?php
2
/**
3
 * File: SpamTestHandler.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Handler\SpamTest;
10
11
use MSlwk\FreshMail\Handler\AbstractHandler;
12
13
/**
14
 * Class SpamTestHandler
15
 *
16
 * @package MSlwk\FreshMail\Handler\SpamTest
17
 */
18
class SpamTestHandler extends AbstractHandler
19
{
20
    const API_ENDPOINT = '/rest/spam_test/check';
21
22
    /**
23
     * @param string $subject
24
     * @param string $content
25
     * @param string $fromEmail
26
     * @param string $fromName
27
     * @return \stdClass
28
     */
29 42
    public function spamCheck(
30
        string $subject,
31
        string $content,
32
        string $fromEmail = '',
33
        string $fromName = ''
34
    ): \stdClass {
35 42
        $getParameters = [];
36 12
        $postParameters = [
37 42
            'subject' => $subject,
38 42
            'html' => $content,
39
            'from' => $fromEmail ?: null,
40
            'from_name' => $fromName ?: null
41
        ];
42
43 30
        $postParameters = array_filter($postParameters, function ($value) {
44 42
            return $value !== null;
45 42
        });
46 42
        $response = $this->processRequest($getParameters, $postParameters);
47 7
        return $response;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 7
    protected function getApiEndpoint(): string
54
    {
55 7
        return self::API_ENDPOINT;
56
    }
57
}
58