GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Card   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 130
ccs 0
cts 50
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 6 2
A title() 0 10 2
A url() 0 6 1
A image() 0 6 1
A subtitle() 0 10 2
A toArray() 0 12 3
A jsonSerialize() 0 4 1
1
<?php
2
3
namespace NotificationChannels\Facebook\Components;
4
5
use JsonSerializable;
6
use NotificationChannels\Facebook\Exceptions\CouldNotCreateCard;
7
use NotificationChannels\Facebook\Traits\HasButtons;
8
9
/**
10
 * Class Card.
11
 */
12
class Card implements JsonSerializable
13
{
14
    use HasButtons;
15
16
    /** @var array Payload */
17
    protected $payload = [];
18
19
    /**
20
     * Create a Card.
21
     *
22
     * @param  string  $title
23
     *
24
     * @throws CouldNotCreateCard
25
     * @return static
26
     */
27
    public static function create(string $title = ''): self
28
    {
29
        return new static($title);
30
    }
31
32
    /**
33
     * Create Card constructor.
34
     *
35
     * @param  string  $title
36
     *
37
     * @throws CouldNotCreateCard
38
     */
39
    public function __construct(string $title = '')
40
    {
41
        if ($title !== '') {
42
            $this->title($title);
43
        }
44
    }
45
46
    /**
47
     * Set Button Title.
48
     *
49
     * @param  string  $title
50
     *
51
     * @throws CouldNotCreateCard
52
     * @return $this
53
     */
54
    public function title(string $title): self
55
    {
56
        if (mb_strlen($title) > 80) {
57
            throw CouldNotCreateCard::titleLimitExceeded($title);
58
        }
59
60
        $this->payload['title'] = $title;
61
62
        return $this;
63
    }
64
65
    /**
66
     * Set Card Item Url.
67
     *
68
     * @param  string  $itemUrl
69
     *
70
     * @return $this
71
     */
72
    public function url(string $itemUrl): self
73
    {
74
        $this->payload['item_url'] = $itemUrl;
75
76
        return $this;
77
    }
78
79
    /**
80
     * Set Card Image Url.
81
     *
82
     * @param  string  $imageUrl  Image ratio should be 1.91:1
83
     *
84
     * @return $this
85
     */
86
    public function image(string $imageUrl): self
87
    {
88
        $this->payload['image_url'] = $imageUrl;
89
90
        return $this;
91
    }
92
93
    /**
94
     * Set Card Subtitle.
95
     *
96
     * @param  string  $subtitle
97
     *
98
     * @throws CouldNotCreateCard
99
     * @return $this
100
     */
101
    public function subtitle(string $subtitle): self
102
    {
103
        if (mb_strlen($subtitle) > 80) {
104
            throw CouldNotCreateCard::subtitleLimitExceeded($subtitle);
105
        }
106
107
        $this->payload['subtitle'] = $subtitle;
108
109
        return $this;
110
    }
111
112
    /**
113
     * Returns a payload for API request.
114
     *
115
     * @throws CouldNotCreateCard
116
     * @return array
117
     */
118
    public function toArray(): array
119
    {
120
        if (! isset($this->payload['title'])) {
121
            throw CouldNotCreateCard::titleNotProvided();
122
        }
123
124
        if (count($this->buttons) > 0) {
125
            $this->payload['buttons'] = $this->buttons;
126
        }
127
128
        return $this->payload;
129
    }
130
131
    /**
132
     * Convert the object into something JSON serializable.
133
     *
134
     * @throws CouldNotCreateCard
135
     * @return mixed
136
     */
137
    public function jsonSerialize()
138
    {
139
        return $this->toArray();
140
    }
141
}
142