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

Png   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 76.92%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 3
A load() 0 9 2
A save() 0 5 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 Png
12
 * Portable network graphics format
13
 * @package kalanis\kw_images\Graphics\Format
14
 */
15
class Png extends AFormat
16
{
17
    /**
18
     * @param IIMTranslations|null $lang
19
     * @throws ImagesException
20
     */
21 14
    public function __construct(?IIMTranslations $lang = null)
22
    {
23 14
        $this->setLang($lang);
24 14
        if (!function_exists('imagecreatefrompng') || !function_exists('imagepng')) {
25
            // @codeCoverageIgnoreStart
26
            throw new ImagesException($this->getLang()->imImageMagicLibNotPresent());
27
        }
28
        // @codeCoverageIgnoreEnd
29 14
    }
30
31 14
    public function load(string $path)
32
    {
33 14
        $result = imagecreatefrompng($path);
34 14
        if (false === $result) {
35
            // @codeCoverageIgnoreStart
36
            throw new ImagesException($this->getLang()->imCannotCreateFromResource());
37
        }
38
        // @codeCoverageIgnoreEnd
39 14
        return $result;
40
    }
41
42 10
    public function save(string $path, $resource): void
43
    {
44 10
        if (!imagepng($resource, $path)) {
45
            // @codeCoverageIgnoreStart
46
            throw new ImagesException($this->getLang()->imCannotSaveResource());
47
        }
48
        // @codeCoverageIgnoreEnd
49 10
    }
50
}
51