GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 52ec30...2a1075 )
by Florian
03:17
created

QueryType::generateFacetChoices()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Stinger Entity Search package.
5
 *
6
 * (c) Oliver Kotte <[email protected]>
7
 * (c) Florian Meyer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
namespace StingerSoft\EntitySearchBundle\Model;
13
14
use Symfony\Component\Form\AbstractType;
15
use Symfony\Component\OptionsResolver\OptionsResolver;
16
use Symfony\Component\Form\FormBuilderInterface;
17
use Symfony\Component\Form\Extension\Core\Type\SearchType;
18
use Symfony\Component\Translation\TranslatorInterface;
19
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
20
use StingerSoft\EntitySearchBundle\Model\Result\FacetSet;
21
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
22
23
class QueryType extends AbstractType {
24
25
	public function buildForm(FormBuilderInterface $builder, array $options) {
26
		$builder->add('term', SearchType::class, array(
27
			'label' => 'stinger_soft_entity_search.forms.query.term.label' 
28
		));
29
		/**
30
		 *
31
		 * @var ResultSet $result
32
		 */
33
		$result = $options['results'];
34
		$this->createFacets($builder, $result->getFacets());
35
		$builder->add('filter', SubmitType::class, array(
36
			'label' => 'stinger_soft_entity_search.forms.query.filter.label' 
37
		));
38
		$builder->add('clear', SubmitType::class, array(
39
			'label' => 'stinger_soft_entity_search.forms.query.clear.label' 
40
		));
41
	}
42
43
	/**
44
	 *
45
	 * @param FormBuilderInterface $builder        	
46
	 * @param FacetSet $facets        	
47
	 */
48
	protected function createFacets(FormBuilderInterface $builder, FacetSet $facets) {
49
		foreach($facets->getFacets() as $facetType => $facetValues) {
50
			$builder->add('facet_' . $facetType, ChoiceType::class, array(
51
				'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label',
52
				'multiple' => true,
53
				'expanded' => true,
54
				'choices_as_values' => true,
55
				'choice' => $this->generateFacetChoices($facetType, $facetValues) 
56
			));
57
		}
58
	}
59
60
	/**
61
	 *
62
	 * @param string $facetType        	
63
	 * @param array $facets        	
64
	 */
65
	protected function generateFacetChoices($facetType, array $facets) {
0 ignored issues
show
Unused Code introduced by
The parameter $facetType is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
		$choices = array();
67
		
68
		foreach($facets as $facet => $count) {
69
			if($count == 0)
70
				break;
71
			$choices[$facet] = $facet . ' (' . $count . ')';
72
		}
73
		return $choices;
74
	}
75
76
	/**
77
	 *
78
	 * {@inheritdoc}
79
	 *
80
	 */
81
	public function configureOptions(OptionsResolver $resolver) {
82
		$resolver->setDefault('data_class', Query::class);
83
		$resolver->setDefault('translation_domain', 'StingerSoftEntitySearchBundle');
84
		
85
		$resolver->setRequired('result', null);
0 ignored issues
show
Unused Code introduced by
The call to OptionsResolver::setRequired() has too many arguments starting with null.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
86
		$resolver->setAllowedTypes('result', ResultSet::class);
87
		
88
		$resolver->setRequired('translator');
89
		$resolver->setAllowedTypes('translator', TranslatorInterface::class);
90
	}
91
}