Passed
Push — main ( 1a1ee7...5cb4cc )
by Tan
25:44 queued 13:14
created

WebhookException   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 10
eloc 19
dl 0
loc 95
rs 10
c 1
b 1
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getWebHookInfo() 0 8 2
A __construct() 0 6 1
A create() 0 6 1
A delete() 0 8 2
A getUpdates() 0 8 2
A set() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CSlant\TelegramGitNotifier\Exceptions;
6
7
use Throwable;
8
9
/**
10
 * Class WebhookException
11
 * 
12
 * Exception thrown when an error occurs during webhook operations.
13
 * Provides factory methods for common webhook-related errors.
14
 */
15
final class WebhookException extends TelegramGitNotifierException
16
{
17
    /**
18
     * Create a new WebhookException instance
19
     *
20
     * @param string $message The exception message
21
     * @param int $code The exception code
22
     * @param Throwable|null $previous The previous exception
23
     */
24
    public function __construct(
25
        string $message = 'An error occurred during webhook operation',
26
        int $code = 0,
27
        ?Throwable $previous = null
28
    ) {
29
        parent::__construct($message, $code, $previous);
30
    }
31
32
    /**
33
     * Create a new exception instance with a custom message
34
     *
35
     * @param string $message The exception message
36
     * @param int $code The exception code
37
     * @param Throwable|null $previous The previous exception
38
     * @return static
39
     */
40
    public static function create(
41
        string $message,
42
        int $code = 0,
43
        ?Throwable $previous = null
44
    ): self {
45
        return new self($message, $code, $previous);
46
    }
47
48
    /**
49
     * Exception thrown when setting up the webhook fails
50
     *
51
     * @param string|null $details Additional error details
52
     * @return self
53
     */
54
    public static function set(?string $details = null): self
55
    {
56
        $message = 'Failed to set webhook';
57
        if ($details) {
58
            $message .= ": {$details}";
59
        }
60
        
61
        return new self($message);
62
    }
63
64
    /**
65
     * Exception thrown when deleting the webhook fails
66
     *
67
     * @param string|null $details Additional error details
68
     * @return self
69
     */
70
    public static function delete(?string $details = null): self
71
    {
72
        $message = 'Failed to delete webhook';
73
        if ($details) {
74
            $message .= ": {$details}";
75
        }
76
        
77
        return new self($message);
78
    }
79
80
    /**
81
     * Exception thrown when getting updates fails
82
     *
83
     * @param string|null $details Additional error details
84
     * @return self
85
     */
86
    public static function getUpdates(?string $details = null): self
87
    {
88
        $message = 'Failed to get updates';
89
        if ($details) {
90
            $message .= ": {$details}";
91
        }
92
        
93
        return new self($message);
94
    }
95
96
    /**
97
     * Exception thrown when getting webhook info fails
98
     *
99
     * @param string|null $details Additional error details
100
     * @return self
101
     */
102
    public static function getWebHookInfo(?string $details = null): self
103
    {
104
        $message = 'Failed to get webhook info';
105
        if ($details) {
106
            $message .= ": {$details}";
107
        }
108
        
109
        return new self($message);
110
    }
111
}
112