Total Complexity | 5 |
Total Lines | 78 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | class File extends Attachment |
||
10 | { |
||
11 | /** |
||
12 | * @var null|string |
||
13 | */ |
||
14 | protected $url; |
||
15 | |||
16 | /** |
||
17 | * @var null|bool |
||
18 | */ |
||
19 | protected $reusable; |
||
20 | |||
21 | /** |
||
22 | * @var null|string |
||
23 | */ |
||
24 | protected $attachmentId; |
||
25 | |||
26 | /** |
||
27 | * File constructor. |
||
28 | * |
||
29 | * @param string $url |
||
30 | * @param bool|null $reusable |
||
31 | * @param string $type |
||
32 | * |
||
33 | * @throws \InvalidArgumentException |
||
34 | */ |
||
35 | 6 | public function __construct($url, ?bool $reusable = null, $type = Attachment::TYPE_FILE) |
|
36 | { |
||
37 | 6 | parent::__construct($type); |
|
38 | |||
39 | 6 | if ($this->isAttachmentId($url)) { |
|
40 | 1 | $this->attachmentId = $url; |
|
41 | } else { |
||
42 | 5 | $this->isValidUrl($url); |
|
43 | 5 | $this->url = $url; |
|
44 | } |
||
45 | |||
46 | 6 | $this->reusable = $reusable; |
|
47 | 6 | } |
|
48 | |||
49 | /** |
||
50 | * @param string $url |
||
51 | * @param bool|null $reusable |
||
52 | * |
||
53 | * @throws \InvalidArgumentException |
||
54 | * |
||
55 | * @return \Kerox\Messenger\Model\Message\Attachment\File |
||
56 | */ |
||
57 | 2 | public static function create($url, ?bool $reusable = null): self |
|
58 | { |
||
59 | 2 | return new self($url, $reusable); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param $value |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | 6 | private function isAttachmentId($value): bool |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * @return array |
||
74 | */ |
||
75 | 6 | public function toArray(): array |
|
87 | } |
||
88 | } |
||
89 |