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

AbstractValueViewHelper::getValueFromArguments()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 8
cp 0.875
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
crap 3.0175
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