Conditions | 5 |
Paths | 5 |
Total Lines | 21 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 5.0592 |
Changes | 0 |
1 | <?php |
||
29 | 3 | public function __construct(string $path, string $type = null) |
|
30 | { |
||
31 | 3 | $content = $path; |
|
32 | 3 | if (substr_count($path, PHP_EOL) === 0 && file_exists($path)) { |
|
33 | 2 | $type = exif_imagetype($path); |
|
34 | 2 | if (!isset(self::IMAGE_TYPE_MAP[$type])) { |
|
35 | throw new UnknownImageTypeException(); |
||
36 | } |
||
37 | 2 | $type = self::IMAGE_TYPE_MAP[$type]; |
|
38 | 2 | $content = file_get_contents($path); |
|
39 | } |
||
40 | 3 | if (!in_array($type, [ |
|
41 | 3 | self::IMAGE_TYPE_BMP, self::IMAGE_TYPE_GIF, self::IMAGE_TYPE_JPG, self::IMAGE_TYPE_PNG, |
|
42 | 3 | self::IMAGE_TYPE_PSD, self::IMAGE_TYPE_TIFF |
|
43 | ]) |
||
44 | ) { |
||
45 | throw new UnknownImageTypeException(); |
||
46 | } |
||
47 | 3 | $this->content = $content; |
|
48 | 3 | $this->type = $type; |
|
49 | 3 | } |
|
50 | |||
66 |