Passed
Push — master ( e55157...ed38f6 )
by Timo
27:41
created

AbstractValueViewHelper::getNameFromArguments()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.4746

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
ccs 5
cts 8
cp 0.625
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.4746
1
<?php
2
namespace ApacheSolrForTypo3\Solr\ViewHelpers\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\Domain\Search\ResultSet\SearchResultSet;
20
use ApacheSolrForTypo3\Solr\ViewHelpers\Uri\AbstractUriViewHelper;
21
22
/**
23
 * Class FacetAddOptionViewHelper
24
 *
25
 * @author Frans Saris <[email protected]>
26
 * @author Timo Hund <[email protected]>
27
 * @package ApacheSolrForTypo3\Solr\ViewHelpers\Link
28
 */
29
abstract class AbstractValueViewHelper extends AbstractUriViewHelper
30
{
31
    /**
32
     * Initializes the arguments
33
     */
34 3
    public function initializeArguments()
35
    {
36 3
        parent::initializeArguments();
37 3
        $this->registerArgument('facet', AbstractFacet::class, 'The facet', false, null);
38 3
        $this->registerArgument('facetName', 'string', 'The facet name', false, null);
39 3
        $this->registerArgument('facetItem', AbstractFacetItem::class, 'The facet item', false, null);
40 3
        $this->registerArgument('facetItemValue', 'string', 'The facet item', false, null);
41 3
        $this->registerArgument('resultSet', SearchResultSet::class, 'The result set', false, null);
42 3
    }
43
44
    /**
45
     * @param $arguments
46
     * @return string
47
     * @throws \InvalidArgumentException
48
     */
49 33
    protected static function getValueFromArguments($arguments)
50
    {
51 33
        if (isset($arguments['facetItem'])) {
52
            /** @var  $facetItem AbstractFacetItem */
53 33
            $facetItem = $arguments['facetItem'];
54 33
            $facetValue = $facetItem->getUriValue();
55 1
        } elseif (isset($arguments['facetItemValue'])) {
56 1
            $facetValue = $arguments['facetItemValue'];
57
        } else {
58
            throw new \InvalidArgumentException('No facetItem was passed, please pass either facetItem or facetItemValue');
59
        }
60
61 33
        return $facetValue;
62
    }
63
64
    /**
65
     * @param $arguments
66
     * @return string
67
     * @throws \InvalidArgumentException
68
     */
69 33
    protected static function getNameFromArguments($arguments)
70
    {
71 33
        if (isset($arguments['facet'])) {
72
            /** @var  $facet AbstractFacet */
73 33
            $facet = $arguments['facet'];
74 33
            $facetName = $facet->getName();
75
        } elseif (isset($arguments['facetName'])) {
76
            $facetName = $arguments['facetName'];
77
        } else {
78
            throw new \InvalidArgumentException('No facet was passed, please pass either facet or facetName');
79
        }
80
81 33
        return $facetName;
82
    }
83
84
    /**
85
     * @param $arguments
86
     * @return string
87
     * @throws \InvalidArgumentException
88
     */
89 33
    protected static function getResultSetFromArguments($arguments)
90
    {
91 33
        if (isset($arguments['facet'])) {
92
            /** @var  $facet AbstractFacet */
93 33
            $facet = $arguments['facet'];
94 33
            $resultSet = $facet->getResultSet();
95
        } elseif (isset($arguments['facetName'])) {
96
            $resultSet = $arguments['resultSet'];
97
        } else {
98
            throw new \InvalidArgumentException('No facet was passed, please pass either facet or resultSet');
99
        }
100
101 33
        return $resultSet;
102
    }
103
}
104