Passed
Push — master ( 8feef3...f9dc8e )
by Petr
09:08 queued 06:38
created

Xbm::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.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
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 Xbm
12
 * X BitMap
13
 * @package kalanis\kw_images\Graphics\Format
14
 */
15
class Xbm 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->setLang($lang);
24 1
        if (!function_exists('imagecreatefromxbm') || !function_exists('imagexbm')) {
25
            // @codeCoverageIgnoreStart
26
            throw new ImagesException($this->getLang()->imImageMagicLibNotPresent());
27
        }
28
        // @codeCoverageIgnoreEnd
29 1
    }
30
31 1
    public function load(string $path)
32
    {
33 1
        $result = imagecreatefromxbm($path);
34 1
        if (false === $result) {
35
            // @codeCoverageIgnoreStart
36
            throw new ImagesException($this->getLang()->imCannotCreateFromResource());
37
        }
38
        // @codeCoverageIgnoreEnd
39 1
        return $result;
40
    }
41
42 1
    public function save(string $path, $resource): void
43
    {
44 1
        if (!imagexbm($resource, $path)) {
45
            // @codeCoverageIgnoreStart
46
            throw new ImagesException($this->getLang()->imCannotSaveResource());
47
        }
48
        // @codeCoverageIgnoreEnd
49 1
    }
50
}
51