Passed
Push — trunk ( 243220...db381d )
by Christian
13:44 queued 16s
created

NewsletterException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 29
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A newsletterThrottled() 0 7 1
A recipientNotFound() 0 13 2
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Content\Newsletter;
4
5
use Shopware\Core\Content\Newsletter\Exception\NewsletterRecipientNotFoundException;
6
use Shopware\Core\Framework\Feature;
7
use Shopware\Core\Framework\HttpException;
8
use Shopware\Core\Framework\Log\Package;
9
use Symfony\Component\HttpFoundation\Response;
10
11
#[Package('checkout')]
12
class NewsletterException extends HttpException
13
{
14
    public const NEWSLETTER_RECIPIENT_NOT_FOUND_CODE = 'CONTENT__NEWSLETTER_RECIPIENT_NOT_FOUND';
15
    public const NEWSLETTER_RECIPIENT_THROTTLED = 'CONTENT__NEWSLETTER_RECIPIENT_THROTTLED';
16
17
    public static function recipientNotFound(
18
        string $identifier,
19
        string $value
20
    ): self {
21
        if (!Feature::isActive('v6.6.0.0')) {
22
            return new NewsletterRecipientNotFoundException($identifier, $value);
0 ignored issues
show
Deprecated Code introduced by
The class Shopware\Core\Content\Ne...ipientNotFoundException has been deprecated: tag:v6.6.0 - reason:remove-exception - Will be removed, use NewsletterException::recipientNotFound instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
            return /** @scrutinizer ignore-deprecated */ new NewsletterRecipientNotFoundException($identifier, $value);
Loading history...
23
        }
24
25
        return new self(
26
            Response::HTTP_BAD_REQUEST,
27
            self::NEWSLETTER_RECIPIENT_NOT_FOUND_CODE,
28
            'The NewsletterRecipient with the identifier "{{ identifier }}" - {{ value }} was not found.',
29
            ['identifier' => $identifier, 'value' => $value]
30
        );
31
    }
32
33
    public static function newsletterThrottled(int $waitTime): NewsletterException
34
    {
35
        return new self(
36
            Response::HTTP_TOO_MANY_REQUESTS,
37
            self::NEWSLETTER_RECIPIENT_THROTTLED,
38
            'Too many requests, try again in {{ seconds }} seconds.',
39
            ['seconds' => $waitTime],
40
        );
41
    }
42
}
43