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

Wbmp::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
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 Wbmp
12
 * Wap bitmap image
13
 * @package kalanis\kw_images\Graphics\Format
14
 */
15
class Wbmp 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('imagecreatefromwbmp') || !function_exists('imagewbmp')) {
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 = imagecreatefromwbmp($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 (!imagewbmp($resource, $path)) {
45
            // @codeCoverageIgnoreStart
46
            throw new ImagesException($this->getImLang()->imCannotSaveResource());
47
        }
48
        // @codeCoverageIgnoreEnd
49
    }
50
}
51