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

AnimatedGif   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 42
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A createFromStates() 0 4 1
A get() 0 4 1
A save() 0 4 1
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