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.
Completed
Push — master ( 8475b5...49338a )
by Irfaq
04:00
created

Card::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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