Passed
Push — master ( 77fb6a...d5753b )
by Petr
08:43
created

Gif   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 32
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 3
A save() 0 5 2
A load() 0 9 2
1
<?php
2
3
namespace kalanis\kw_images\Graphics\Format;
4
5
6
use kalanis\kw_images\ImagesException;
7
use kalanis\kw_images\Interfaces\IIMTranslations;
8
9
10
/**
11
 * Class Gif
12
 * Graphics Interchange Format (GIF)
13
 * @package kalanis\kw_images\Graphics\Format
14
 */
15
class Gif extends AFormat
16
{
17
    /**
18
     * @param IIMTranslations|null $lang
19
     * @throws ImagesException
20
     */
21 1
    public function __construct(?IIMTranslations $lang = null)
22
    {
23 1
        $this->setImLang($lang);
24 1
        if (!function_exists('imagecreatefromgif') || !function_exists('imagegif')) {
25
            // @codeCoverageIgnoreStart
26
            throw new ImagesException($this->getImLang()->imImageMagicLibNotPresent());
27
        }
28
        // @codeCoverageIgnoreEnd
29
    }
30
31 1
    public function load(string $path)
32
    {
33 1
        $result = imagecreatefromgif($path);
34 1
        if (false === $result) {
35
            // @codeCoverageIgnoreStart
36
            throw new ImagesException($this->getImLang()->imCannotCreateFromResource());
37
        }
38
        // @codeCoverageIgnoreEnd
39 1
        return $result;
40
    }
41
42 1
    public function save(?string $path, $resource): void
43
    {
44 1
        if (!imagegif($resource, $path)) {
45
            // @codeCoverageIgnoreStart
46
            throw new ImagesException($this->getImLang()->imCannotSaveResource());
47
        }
48
        // @codeCoverageIgnoreEnd
49
    }
50
}
51