Passed
Push — master ( 6c011a...8a7749 )
by Romain
36s
created

Image::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment;
6
7
use Kerox\Messenger\Model\Message\Attachment;
8
9
class Image extends File
10
{
11
    protected const ALLOWED_EXTENSIONS = ['jpg', 'png', 'gif'];
12
13
    /**
14
     * Image constructor.
15
     *
16
     * @param string    $url
17
     * @param bool|null $reusable
18
     *
19
     * @throws \InvalidArgumentException
20
     */
21 2
    public function __construct($url, ?bool $reusable = null)
22
    {
23 2
        $this->isValidExtension($url, $this->getAllowedExtensions());
24
25 2
        parent::__construct($url, $reusable, Attachment::TYPE_IMAGE);
26 2
    }
27
28
    /**
29
     * @param string    $url
30
     * @param bool|null $reusable
31
     *
32
     * @throws \InvalidArgumentException
33
     *
34
     * @return \Kerox\Messenger\Model\Message\Attachment\File
35
     */
36 1
    public static function create($url, ?bool $reusable = null): File
37
    {
38 1
        return new self($url, $reusable);
39
    }
40
41
    /**
42
     * @return array
43
     */
44 2
    protected function getAllowedExtensions(): array
45
    {
46 2
        return self::ALLOWED_EXTENSIONS;
47
    }
48
}
49