Passed
Push — master ( a95893...a4d2df )
by Timo
57s
created

AbstractValueViewHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 33
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 7 1
A getValueFromArguments() 0 14 3
1
<?php
2
namespace ApacheSolrForTypo3\Solr\ViewHelpers\Frontend\Uri\Facet;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacet;
18
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacetItem;
19
use ApacheSolrForTypo3\Solr\ViewHelpers\Frontend\Uri\AbstractUriViewHelper;
20
21
/**
22
 * Class FacetAddOptionViewHelper
23
 *
24
 * @author Frans Saris <[email protected]>
25
 * @author Timo Hund <[email protected]>
26
 * @package ApacheSolrForTypo3\Solr\ViewHelpers\Link
27
 */
28
abstract class AbstractValueViewHelper extends AbstractUriViewHelper
29
{
30
    /**
31
     * Initializes the arguments
32
     */
33 2
    public function initializeArguments()
34
    {
35 2
        parent::initializeArguments();
36 2
        $this->registerArgument('facet', AbstractFacet::class, 'The facet', true);
37 2
        $this->registerArgument('facetItem', AbstractFacetItem::class, 'The facet item', false, null);
38 2
        $this->registerArgument('facetItemValue', 'string', 'The facet item', false, null);
39 2
    }
40
41
    /**
42
     * @param $arguments
43
     * @return string
44
     * @throws \InvalidArgumentException
45
     */
46 21
    protected static function getValueFromArguments($arguments)
47
    {
48 21
        if (isset($arguments['facetItem'])) {
49
            /** @var  $facetItem AbstractFacetItem */
50 21
            $facetItem = $arguments['facetItem'];
51 21
            $facetValue = $facetItem->getUriValue();
52 1
        } elseif (isset($arguments['facetItemValue'])) {
53 1
            $facetValue = $arguments['facetItemValue'];
54
        } else {
55
            throw new \InvalidArgumentException('No facetItem was passed, please pass either facetItem or facetItemValue');
56
        }
57
58 21
        return $facetValue;
59
    }
60
}
61