DummyService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
dl 0
loc 38
rs 10
c 2
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A systemServiceId() 0 3 1
A sendEmail() 0 15 4
A canUseService() 0 3 1
1
<?php
2
3
use kalanis\EmailApi\Basics;
4
use kalanis\EmailApi\Interfaces;
5
use kalanis\EmailApi\Exceptions;
6
7
8
class DummyService implements Interfaces\ISending
9
{
10
    protected bool $canUseService = true;
11
    protected bool $getPassedResult = true;
12
    protected bool $getFailedResult = true;
13
14
    public function __construct(bool $canUseService = true, bool $getPassedResult = true, bool $getFailedResult = true)
15
    {
16
        $this->canUseService = $canUseService;
17
        $this->getPassedResult = $getPassedResult;
18
        $this->getFailedResult = $getFailedResult;
19
    }
20
21
    public function canUseService(): bool
22
    {
23
        return boolval($this->canUseService);
24
    }
25
26
    public function systemServiceId(): int
27
    {
28
        return static::SERVICE_TESTING;
29
    }
30
31
    public function sendEmail(Interfaces\IContent $content, Interfaces\IEmailUser $to, ?Interfaces\IEmailUser $from = null, ?Interfaces\IEmailUser $replyTo = null, $toDisabled = false): Basics\Result
32
    {
33
        if ($this->getPassedResult) {
34
            return new Basics\Result(
35
                !empty($content->getHtmlBody())
36
                && !empty($to->getEmail()),
37
                'Dummy service with check'
38
            );
39
        }
40
41
        if ($this->getFailedResult) {
42
            return new Basics\Result(false, 'died');
43
        }
44
45
        throw new Exceptions\EmailException('die on send');
46
    }
47
}
48