| 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 | 2 | public function __construct(string $path, string $type = null) |
|
| 30 | { |
||
| 31 | 2 | $content = $path; |
|
| 32 | 2 | if (substr_count($path, PHP_EOL) === 0 && file_exists($path)) { |
|
| 33 | 1 | $type = exif_imagetype($path); |
|
| 34 | 1 | if (!isset(self::IMAGE_TYPE_MAP[$type])) { |
|
| 35 | throw new UnknownImageTypeException(); |
||
| 36 | } |
||
| 37 | 1 | $type = self::IMAGE_TYPE_MAP[$type]; |
|
| 38 | 1 | $content = file_get_contents($path); |
|
| 39 | } |
||
| 40 | 2 | if (!in_array($type, [ |
|
| 41 | 2 | self::IMAGE_TYPE_BMP, self::IMAGE_TYPE_GIF, self::IMAGE_TYPE_JPG, self::IMAGE_TYPE_PNG, |
|
| 42 | 2 | self::IMAGE_TYPE_PSD, self::IMAGE_TYPE_TIFF |
|
| 43 | ]) |
||
| 44 | ) { |
||
| 45 | throw new UnknownImageTypeException(); |
||
| 46 | } |
||
| 47 | 2 | $this->content = $content; |
|
| 48 | 2 | $this->type = $type; |
|
| 49 | 2 | } |
|
| 50 | |||
| 61 |