FlockAttachmentView   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 13
lcom 4
cbo 2
dl 0
loc 113
ccs 0
cts 40
cp 0
rs 10
c 1
b 1
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A flockml() 0 6 1
A image() 0 8 1
B widget() 0 19 6
B html() 0 16 5
1
<?php
2
3
namespace NotificationChannels\Flock;
4
5
use Closure;
6
use NotificationChannels\Flock\Exceptions\CouldNotSendNotification;
7
8
class FlockAttachmentView
9
{
10
    /**
11
     * Displays an attachment widget inside the chat screen in desktop,
12
     * or pops up a modal when the attachment is opened on mobile.
13
     *
14
     * @var array
15
     */
16
    public $widget;
17
18
    /**
19
     * Displays the HTML string inside the chat screen in desktop (using an iframe).
20
     *
21
     * @var array
22
     */
23
    public $html;
24
25
    /**
26
     * A string containing FlockML content. It is displayed inside the chat screen on both desktop and mobile.
27
     *
28
     * @var string
29
     */
30
    public $flockml;
31
32
    /**
33
     * An image for the attachment.
34
     *
35
     * @var array
36
     */
37
    public $image;
38
39
    /**
40
     * Create an widget.
41
     *
42
     * @param   string   $src
43
     * @param int|null $height
44
     * @param int|null $width
45
     *
46
     * @return $this
47
     */
48
    public function widget($src, $height = null, $width = null)
49
    {
50
        if (! filter_var($src, FILTER_VALIDATE_URL)) {
51
            throw CouldNotSendNotification::flockAttachmentViewWidgetException('Source of widget in attachment is missing or invalid.');
52
        }
53
        $this->widget['src'] = $src;
54
55
        if (! filter_var($height, FILTER_VALIDATE_INT) || $height <= 0) {
56
            throw CouldNotSendNotification::flockAttachmentViewWidgetException('Height of widget in attachment is missing or invalid.');
57
        }
58
        $this->widget['height'] = $height;
59
60
        if (! filter_var($width, FILTER_VALIDATE_INT) || $width <= 0) {
61
            throw CouldNotSendNotification::flockAttachmentViewWidgetException('Width of widget in attachment is missing or invalid.');
62
        }
63
        $this->widget['width'] = $width;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param  string    $inline
70
     * @param int|null $height
71
     * @param int|null $width
72
     *
73
     * @return $this
74
     */
75
    public function html($inline, $height = null, $width = null)
76
    {
77
        $this->html['inline'] = $inline;
78
79
        if (! filter_var($height, FILTER_VALIDATE_INT) || $height <= 0) {
80
            throw CouldNotSendNotification::flockAttachmentViewHtmlException('Height of inline html in attachment is missing or invalid.');
81
        }
82
        $this->html['height'] = $height;
83
84
        if (! filter_var($width, FILTER_VALIDATE_INT) || $width <= 0) {
85
            throw CouldNotSendNotification::flockAttachmentViewHtmlException('Width of inline html in attachment is missing or invalid.');
86
        }
87
        $this->html['width'] = $width;
88
89
        return $this;
90
    }
91
92
    /**
93
     * Create and FlockML sting.
94
     *
95
     * @param string $string
96
     *
97
     * @return $this
98
     */
99
    public function flockml($string)
100
    {
101
        $this->flockml = $string;
102
103
        return $this;
104
    }
105
106
    /**
107
     * Define an image for the attachment.
108
     *
109
     * @param  \Closure  $callback
110
     * @return $this
111
     */
112
    public function image(Closure $callback)
113
    {
114
        $this->image = $i = new FlockAttachmentViewImage;
0 ignored issues
show
Documentation Bug introduced by
It seems like $i = new \NotificationCh...ckAttachmentViewImage() of type object<NotificationChann...ockAttachmentViewImage> is incompatible with the declared type array of property $image.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
115
116
        $callback($i);
117
118
        return $this;
119
    }
120
}
121