Url   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A load() 0 6 1
A upload() 0 6 1
1
<?php
2
3
namespace Bex\Behat\ScreenshotExtension\Driver;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
class Url extends Local implements ImageDriverInterface
9
{
10
    const CONFIG_PARAM_SCREENSHOT_URL = 'screenshot_url';
11
12
    private $screenshotUrl;
13
    private $screenshotDirectory;
14
15
    /**
16
     * @param  ArrayNodeDefinition $builder
17
     *
18
     * @return void
19
     */
20
    public function configure(ArrayNodeDefinition $builder)
21
    {
22
        parent::configure($builder);
23
24
        $builder
25
            ->children()
26
                ->scalarNode(self::CONFIG_PARAM_SCREENSHOT_URL)
27
                ->end()
28
            ->end();
0 ignored issues
show
Bug introduced by
The method end() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Config...ion\Builder\TreeBuilder. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
            ->/** @scrutinizer ignore-call */ end();
Loading history...
29
    }
30
31
    /**
32
     * @param  ContainerBuilder $container
33
     * @param  array            $config
34
     *
35
     * @return void
36
     */
37
    public function load(ContainerBuilder $container, array $config)
38
    {
39
        parent::load($container, $config);
40
41
        $this->screenshotUrl  = $config[self::CONFIG_PARAM_SCREENSHOT_URL];
42
        $this->screenshotDirectory = $config[self::CONFIG_PARAM_SCREENSHOT_DIRECTORY];
43
    }
44
45
    /**
46
     * @param string $binaryImage
47
     * @param string $filename
48
     *
49
     * @return string URL to the image
50
     */
51
    public function upload($binaryImage, $filename)
52
    {
53
        $urlToImage = parent::upload($binaryImage, $filename);
54
        $externUrlToImage = str_replace($this->screenshotDirectory, $this->screenshotUrl, $urlToImage);
55
56
        return sprintf("%s or %s", $urlToImage, $externUrlToImage);
57
    }
58
}
59