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

Image   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 38
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAllowedExtensions() 0 3 1
A create() 0 3 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