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

NewsletterException::newsletterThrottled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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