DummyService::systemServiceId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
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