Passed
Push — trunk ( 04838b...ff423b )
by Christian
11:03 queued 15s
created

MailException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A givenMailAgentIsInvalid() 0 7 1
A givenSendMailOptionIsInvalid() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Content\Mail;
4
5
use Shopware\Core\Framework\HttpException;
6
use Shopware\Core\Framework\Log\Package;
7
use Shopware\Core\Framework\ShopwareHttpException;
8
use Symfony\Component\HttpFoundation\Response;
9
10
#[Package('services-settings')]
11
class MailException extends HttpException
12
{
13
    final public const GIVEN_OPTION_INVALID = 'MAIL__GIVEN_OPTION_INVALID';
14
15
    final public const GIVEN_AGENT_INVALID = 'MAIL__GIVEN_AGENT_INVALID';
16
17
    /**
18
     * @param string[] $validOptions
19
     */
20
    public static function givenSendMailOptionIsInvalid(string $option, array $validOptions): ShopwareHttpException
21
    {
22
        return new self(
23
            Response::HTTP_INTERNAL_SERVER_ERROR,
24
            self::GIVEN_OPTION_INVALID,
25
            'Given sendmail option "{{ option }}" is invalid. Available options: {{ validOptions }}',
26
            ['option' => $option, 'validOptions' => implode(', ', $validOptions)]
27
        );
28
    }
29
30
    public static function givenMailAgentIsInvalid(string $agent): ShopwareHttpException
31
    {
32
        return new self(
33
            Response::HTTP_INTERNAL_SERVER_ERROR,
34
            self::GIVEN_AGENT_INVALID,
35
            'Invalid mail agent given "{{ agent }}"',
36
            ['agent' => $agent]
37
        );
38
    }
39
}
40