AnimatedGif::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 1
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