1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Flock; |
4
|
|
|
|
5
|
|
|
use NotificationChannels\Flock\Exceptions\CouldNotSendNotification; |
6
|
|
|
|
7
|
|
|
class FlockAttachmentViewImage |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Image object. |
11
|
|
|
* |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
public $original; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Thumbnail object. |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
public $thumbnail; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Filename for the attached image. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $filename; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Attach origin al image to attachment. |
32
|
|
|
* |
33
|
|
|
* @param string $src |
34
|
|
|
* @param int|null $height |
35
|
|
|
* @param int|null $width |
36
|
|
|
* |
37
|
|
|
* @return $this |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
public function original($src, $height, $width) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
if (! filter_var($src, FILTER_VALIDATE_URL)) { |
42
|
|
|
throw CouldNotSendNotification::flockAttachmentViewImageException('Source of image in attachment is missing or invalid.'); |
43
|
|
|
} |
44
|
|
|
$this->original['src'] = $src; |
45
|
|
|
|
46
|
|
|
if (! filter_var($height, FILTER_VALIDATE_INT) or $height <= 0) { |
47
|
|
|
throw CouldNotSendNotification::flockAttachmentViewImageException('Height of image in attachment is missing or invalid.'); |
48
|
|
|
} |
49
|
|
|
$this->original['height'] = $height; |
50
|
|
|
|
51
|
|
|
if (! filter_var($width, FILTER_VALIDATE_INT) or $width <= 0) { |
52
|
|
|
throw CouldNotSendNotification::flockAttachmentViewImageException('Width of image in attachment is missing or invalid.'); |
53
|
|
|
} |
54
|
|
|
$this->original['width'] = $width; |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Attach thumbnail to attachment. |
61
|
|
|
* |
62
|
|
|
* @param string $src |
63
|
|
|
* @param int|null $height |
64
|
|
|
* @param int|null $width |
65
|
|
|
* |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
|
View Code Duplication |
public function thumbnail($src, $height, $width) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
if (! filter_var($src, FILTER_VALIDATE_URL)) { |
71
|
|
|
throw CouldNotSendNotification::flockAttachmentViewImageException('Source of image in attachment is missing or invalid.'); |
72
|
|
|
} |
73
|
|
|
$this->thumbnail['src'] = $src; |
74
|
|
|
|
75
|
|
|
if (! filter_var($height, FILTER_VALIDATE_INT) or $height <= 0) { |
76
|
|
|
throw CouldNotSendNotification::flockAttachmentViewImageException('Height of image in attachment is missing or invalid.'); |
77
|
|
|
} |
78
|
|
|
$this->thumbnail['height'] = $height; |
79
|
|
|
|
80
|
|
|
if (! filter_var($width, FILTER_VALIDATE_INT) or $width <= 0) { |
81
|
|
|
throw CouldNotSendNotification::flockAttachmentViewImageException('Width of image in attachment is missing or invalid.'); |
82
|
|
|
} |
83
|
|
|
$this->thumbnail['width'] = $width; |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Add file name to attached image. |
90
|
|
|
* |
91
|
|
|
* @param string $filename |
92
|
|
|
* |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function filename($filename) |
96
|
|
|
{ |
97
|
|
|
$this->filename = $filename; |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.