Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PublishException
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 getArticle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPlatform
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Exceptions;
4
5use App\Enums\PlatformEnum;
6use App\Models\Article;
7use Exception;
8use Throwable;
9
10class PublishException extends Exception
11{
12    public function __construct(
13        private readonly Article $article,
14        private readonly PlatformEnum|null $platform,
15        ?Throwable $previous = null
16    ) {
17        $message = "Failed to publish article #$article->id";
18
19        if ($this->platform) {
20            $message .= "  to $platform->value";
21        }
22
23        if ($previous) {
24            $message .= "{$previous->getMessage()}";
25        }
26
27        parent::__construct($message, 0, $previous);
28    }
29
30    public function getArticle(): Article
31    {
32        return $this->article;
33    }
34
35    public function getPlatform(): ?PlatformEnum
36    {
37        return $this->platform;
38    }
39}