Completed
Push — develop ( ebc20b...a36a32 )
by Barry
01:39
created

AnimatedGif::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Barryvanveen\CCA\Generators;
4
5
use Barryvanveen\CCA\Config;
6
use Barryvanveen\CCA\State;
7
use GifCreator\AnimGif;
8
9
class AnimatedGif
10
{
11
    /** @var AnimGif */
12
    protected $animation;
13
14
    /**
15
     * @param Config $config
16
     * @param State[] $states
17
     */
18 9
    protected function __construct(Config $config, array $states)
19
    {
20 9
        $images = [];
21
22 9
        foreach ($states as $state) {
23 9
            $images[] = Gif::createFromState($config, $state)->get();
24
        }
25
26 9
        $this->animation = new AnimGif();
27 9
        $this->animation->create($images);
28 9
    }
29
30
    /**
31
     * @param Config $config
32
     * @param State[] $states
33
     *
34
     * @return AnimatedGif
35
     */
36 9
    public static function createFromStates(Config $config, array $states)
37
    {
38 9
        return new self($config, $states);
39
    }
40
41 3
    public function get(): AnimGif
42
    {
43 3
        return $this->animation;
44
    }
45
46 6
    public function save(string $filename)
47
    {
48 6
        return $this->animation->save($filename);
49
    }
50
}
51