Unsee   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 71
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A configure() 0 10 1
A load() 0 4 1
A upload() 0 4 1
A convertExpireValue() 0 4 1
1
<?php
2
3
namespace Bex\Behat\ScreenshotExtension\Driver;
4
5
use Bex\Behat\ScreenshotExtension\Driver\ImageDriverInterface;
6
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Bex\Behat\ScreenshotExtension\Driver\Service\UnseeApi;
9
10
class Unsee implements ImageDriverInterface
11
{
12
    const CONFIG_PARAM_EXPIRE = 'expire';
13
14
    /**
15
     * @var array
16
     */
17
    private $expireMapping = ['10m' => 600, '30m' => 1800, '1h' => 3600];
18
19
    /**
20
     * @var UnseeApi
21
     */
22
    private $api;
23
24
    /**
25
     * @var int
26
     */
27
    private $expire;
28
29
    /**
30
     * @param UnseeApi $api
31
     */
32
    public function __construct(UnseeApi $api = null)
33
    {
34
        $this->api = $api ?: new UnseeApi();
35
    }
36
37
    /**
38
     * @param  ArrayNodeDefinition $builder
39
     */
40
    public function configure(ArrayNodeDefinition $builder)
41
    {
42
        $builder
43
            ->children()
44
                ->enumNode(self::CONFIG_PARAM_EXPIRE)
45
                    ->values(array('10m', '30m', '1h'))
46
                    ->defaultValue('10m')
47
                ->end()
48
            ->end();
49
    }
50
51
    /**
52
     * @param  ContainerBuilder $container
53
     * @param  array            $config
54
     */
55
    public function load(ContainerBuilder $container, array $config)
56
    {
57
        $this->expire = $this->convertExpireValue($config[self::CONFIG_PARAM_EXPIRE]);
58
    }
59
60
    /**
61
     * @param string $binaryImage
62
     * @param string $filename
63
     *
64
     * @return string URL to the image
65
     */
66
    public function upload($binaryImage, $filename)
67
    {
68
        return $this->api->call($binaryImage, $filename, $this->expire);
69
    }
70
71
    /**
72
     * @param  string $expire
73
     *
74
     * @return int
75
     */
76
    private function convertExpireValue($expire)
77
    {
78
        return $this->expireMapping[$expire];
79
    }
80
}