Passed
Push — master ( 4a0c05...84842d )
by Rafael
137:02 queued 134:07
created

AbstractValueViewHelper::initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.0019

Importance

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