Completed
Push — master ( 59d6ff...569ee7 )
by
unknown
04:23
created

ImgixUrlViewHelper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 79.17%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 64
ccs 19
cts 24
cp 0.7917
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A initializeArguments() 0 6 1
A render() 0 14 3
A getUrlParameters() 0 8 2
A hasUrlParameters() 0 4 1
1
<?php
2
namespace Aoe\Imgix\ViewHelpers;
3
4
use Aoe\Imgix\TYPO3\Configuration;
5
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
6
7
class ImgixUrlViewHelper extends AbstractViewHelper
8
{
9
10
    /**
11
     * @var Configuration
12
     */
13
    private $configuration;
14
15
    /**
16
     * @param Configuration $configuration
17
     */
18 5
    public function __construct(Configuration $configuration)
19
    {
20 5
        $this->configuration = $configuration;
21 5
    }
22
23
    /**
24
     * @return void
25
     */
26
    public function initializeArguments()
27
    {
28
        parent::initializeArguments();
29
        $this->registerArgument('imageUrl', 'string', 'URL to image file', true);
30
        $this->registerArgument('urlParameters', 'array', 'API Parameters to be appended to URL', false);
31
    }
32
33
    /**
34
     * @return string
35
     */
36 5
    public function render()
37
    {
38 5
        if (false === $this->configuration->isEnabled()) {
39 1
            return $this->arguments['imageUrl'];
40
        }
41
42 4
        $url = '//' . $this->configuration->getHost() . '/' . $this->arguments['imageUrl'];
43
44 4
        if ($this->hasUrlParameters()) {
45 3
            $url .= '?' . http_build_query($this->getUrlParameters());
46 3
        }
47
48 4
        return $url;
49
    }
50
51
    /**
52
     * @return array
53
     */
54 4
    private function getUrlParameters()
55
    {
56 4
        $parameters = $this->configuration->getImgixDefaultUrlParameters();
57 4
        if ($this->hasArgument('urlParameters')) {
58 3
            $parameters = array_merge($parameters, $this->arguments['urlParameters']);
59 3
        }
60 4
        return $parameters;
61
    }
62
63
    /**
64
     * @return boolean
65
     */
66 4
    private function hasUrlParameters()
67
    {
68 4
        return sizeof($this->getUrlParameters()) > 0;
69
    }
70
}
71