Completed
Push — master ( 3e8b02...37f80c )
by Florian
16:58
created
Tests/Form/QueryTypeTest.php 1 patch
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -140,6 +140,9 @@
 block discarded – undo
140 140
 // 		$this->assertCount(2, $typeForm->vars['choices']);
141 141
 	}
142 142
 	
143
+	/**
144
+	 * @return ValidatorInterface
145
+	 */
143 146
 	protected function mockValidator() {
144 147
 		$validator = $this->getMockBuilder(ValidatorInterface::class)->setMethods(array('validate', 'getErrors'))->getMockForAbstractClass();
145 148
 		$validator->method('validate')->willReturn(array());
Please login to merge, or discard this patch.
Form/QueryType.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -53,26 +53,26 @@  discard block
 block discarded – undo
53 53
 		$maxChoiceGroupCount = $options['max_choice_group_count'];
54 54
 		$data = array();
55 55
 		
56
-		if($usedFacets && !$result) {
56
+		if ($usedFacets && !$result) {
57 57
 			$data = array();
58
-			foreach($usedFacets as $facetType => $facetTypeOptions) {
58
+			foreach ($usedFacets as $facetType => $facetTypeOptions) {
59 59
 				$facetTypeOptions = is_array($facetTypeOptions) ? $facetTypeOptions : [];
60 60
 				$preferredChoices = $preferredFilterChoices[$facetType] ?? [];
61 61
 				$i = 0;
62
-				$builder->add('facet_' . $facetType, FacetType::class, array_merge(array(
63
-					'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label',
62
+				$builder->add('facet_'.$facetType, FacetType::class, array_merge(array(
63
+					'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label',
64 64
 					'multiple' => true,
65 65
 					'expanded' => true,
66 66
 					'allow_extra_fields' => true,
67
-					'preferred_choices' => function ($val) use ($preferredChoices, $data, $facetType, $maxChoiceGroupCount, &$i) {
68
-						return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($data['facet_' . $facetType]) && in_array($val, $data['facet_' . $facetType]));
67
+					'preferred_choices' => function($val) use ($preferredChoices, $data, $facetType, $maxChoiceGroupCount, &$i) {
68
+						return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($data['facet_'.$facetType]) && in_array($val, $data['facet_'.$facetType]));
69 69
 					} 
70 70
 				), $facetTypeOptions));
71 71
 				unset($i);
72 72
 			}
73 73
 		}
74
-		if($result) {
75
-			$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options, $result) {
74
+		if ($result) {
75
+			$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($options, $result) {
76 76
 				$this->createFacets($event->getForm(), $result->getFacets(), $options, $event->getData());
77 77
 			});
78 78
 		}
@@ -111,19 +111,19 @@  discard block
 block discarded – undo
111 111
 		$selectedFacets = $data->getFacets();
112 112
 		$usedFacets = $options['used_facets'];
113 113
 		
114
-		foreach($facets->getFacets() as $facetType => $facetValues) {
114
+		foreach ($facets->getFacets() as $facetType => $facetValues) {
115 115
 			$preferredChoices = isset($preferredFilterChoices[$facetType]) ? $preferredFilterChoices[$facetType] : array();
116 116
 			
117 117
 			$i = 0;
118 118
 			$facetTypeOptions = isset($usedFacets[$facetType]) ? $usedFacets[$facetType] : [];
119 119
 			$formatter = isset($options['facet_formatter'][$facetType]) ? $options['facet_formatter'][$facetType] : null;
120
-			$builder->add('facet_' . $facetType, FacetType::class, array_merge(array(
121
-				'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label',
120
+			$builder->add('facet_'.$facetType, FacetType::class, array_merge(array(
121
+				'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label',
122 122
 				'multiple' => true,
123 123
 				'expanded' => true,
124 124
 				'allow_extra_fields' => true,
125 125
 				'choices' => $this->generateFacetChoices($facetType, $facetValues, isset($selectedFacets[$facetType]) ? $selectedFacets[$facetType] : array(), $formatter),
126
-				'preferred_choices' => function ($val) use ($preferredChoices, $selectedFacets, $facetType, $maxChoiceGroupCount, &$i) {
126
+				'preferred_choices' => function($val) use ($preferredChoices, $selectedFacets, $facetType, $maxChoiceGroupCount, &$i) {
127 127
 					return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($selectedFacets[$facetType]) && in_array($val, $selectedFacets[$facetType]));
128 128
 				} 
129 129
 			), $facetTypeOptions));
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	protected function generateFacetChoices($facetType, array $facets, array $selectedFacets = array(), $formatter) {
140 140
 		$choices = array();
141
-		foreach($facets as $facet => $count) {
142
-			if($count == 0 && !in_array($facet, $selectedFacets))
141
+		foreach ($facets as $facet => $count) {
142
+			if ($count == 0 && !in_array($facet, $selectedFacets))
143 143
 				continue;
144 144
 			$choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet;
145 145
 		}
146
-		foreach($selectedFacets as $facet) {
147
-			if(isset($facets[$facet])) continue;
146
+		foreach ($selectedFacets as $facet) {
147
+			if (isset($facets[$facet])) continue;
148 148
 			$count = 0;
149 149
 			$choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet;
150 150
 		}
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
 	}
153 153
 	
154 154
 	protected function formatFacet($formatter, $facetType, $facet, $count) {
155
-		$default = $facet . ' (' . $count . ')';
156
-		if(!$formatter) {
155
+		$default = $facet.' ('.$count.')';
156
+		if (!$formatter) {
157 157
 			return $default;
158 158
 		}
159 159
 		return call_user_func($formatter, $facetType, $facet, $count, $default);
Please login to merge, or discard this patch.