Completed
Push — master ( 9e3f36...d6692d )
by Freek
01:30
created

CouldNotSendCampaign::invalidSegmentClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Spatie\EmailCampaigns\Exceptions;
4
5
use Exception;
6
use ErrorException;
7
use Illuminate\Mail\Mailable;
8
use Spatie\EmailCampaigns\Support\Segments\Segment;
9
use Spatie\EmailCampaigns\Mails\CampaignMailable;
10
use Spatie\EmailCampaigns\Mails\UsedInCampaign;
11
use Spatie\EmailCampaigns\Models\Campaign;
12
13
class CouldNotSendCampaign extends Exception
14
{
15
    public static function beingSent(Campaign $campaign): self
16
    {
17
        return new static("The campaign with id `{$campaign->id}` can't be sent, because it is already being sent.");
18
    }
19
20
    public static function invalidMailableClass(Campaign $campaign, string $invalidMailableClass)
21
    {
22
        $mustExtend = CampaignMailable::class;
23
24
        return new static("The campaign with id `{$campaign->id}` can't be sent, because an invalid mailable class `{$invalidMailableClass}` is set. A valid mailable class must extend `{$mustExtend}`.");
25
    }
26
27
    public static function invalidSegmentClass(Campaign $campaign, string $invalidSegmentClass)
28
    {
29
        $mustExtend = Segment::class;
30
31
        return new static("The campaign with id `{$campaign->id}` can't be sent, because an invalid segment class `{$invalidSegmentClass}` is set. A valid segment class must implement `{$mustExtend}`.");
32
    }
33
34
    public static function alreadySent(Campaign $campaign): self
35
    {
36
        return new static("The campaign with id `{$campaign->id}` can't be sent, because it was already sent.");
37
    }
38
39
    public static function noListSet(Campaign $campaign)
40
    {
41
        return new static("The campaign with id `{$campaign->id}` can't be sent, because there is no list set to send it to.");
42
    }
43
44
    public static function noSubjectSet(Campaign $campaign)
45
    {
46
        return new static("The campaign with id `{$campaign->id}` can't be sent, because no subject has been set.");
47
    }
48
49
    public static function noContent(Campaign $campaign): self
50
    {
51
        return new static("The campaign with id `{$campaign->id}` can't be sent because not content has been set.");
52
    }
53
54
    public static function invalidContent(Campaign $campaign, ErrorException $errorException): self
55
    {
56
        return new static("The campaign with id `{$campaign->id}` can't be sent because the content isn't valid. Please check if the html is valid. DOMDocument reported: `{$errorException->getMessage()}`", 0, $errorException);
57
    }
58
}
59