AnimatedGif   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 44
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromStates() 0 3 1
A get() 0 3 1
A save() 0 3 1
A __construct() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Barryvanveen\CCA\Generators;
6
7
use Barryvanveen\CCA\Config;
8
use Barryvanveen\CCA\State;
9
use GifCreator\AnimGif;
10
11
class AnimatedGif
12
{
13
    /** @var AnimGif */
14
    protected $animation;
15
16
    /**
17
     * @param Config $config
18
     * @param State[] $states
19
     *
20
     * @throws \Exception
21
     */
22 9
    protected function __construct(Config $config, array $states)
23
    {
24 9
        $images = [];
25
26 9
        foreach ($states as $state) {
27 9
            $images[] = Gif::createFromState($config, $state)->get();
28
        }
29
30 9
        $this->animation = new AnimGif();
31 9
        $this->animation->create($images);
32 9
    }
33
34
    /**
35
     * @param Config $config
36
     * @param State[] $states
37
     *
38
     * @return AnimatedGif
39
     *
40
     * @throws \Exception
41
     */
42 9
    public static function createFromStates(Config $config, array $states)
43
    {
44 9
        return new self($config, $states);
45
    }
46
47 3
    public function get(): AnimGif
48
    {
49 3
        return $this->animation;
50
    }
51
52 6
    public function save(string $filename)
53
    {
54 6
        return $this->animation->save($filename);
55
    }
56
}
57