Completed
Push — master ( 09d8db...9ac279 )
by Florian
05:02
created
Form/QueryType.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 
101 101
 	/**
102 102
 	 *
103
-	 * @param FormBuilderInterface|Form $builder        	
103
+	 * @param FormInterface $builder        	
104 104
 	 * @param FacetSet $facets        	
105 105
 	 */
106 106
 	protected function createFacets($builder, FacetSet $facets, array $options, $data) {
@@ -143,6 +143,9 @@  discard block
 block discarded – undo
143 143
 		return $choices;
144 144
 	}
145 145
 	
146
+	/**
147
+	 * @param string $facetType
148
+	 */
146 149
 	protected function formatFacet($formatter, $facetType, $facet, $count) {
147 150
 		$default = $facet . ' (' . $count . ')';
148 151
 		if(!$formatter) {
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -53,24 +53,24 @@  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) {
58
+			foreach ($usedFacets as $facetType) {
59 59
 				$preferredChoices = isset($preferredFilterChoices[$facetType]) ? $preferredFilterChoices[$facetType] : array();
60 60
 				$i = 0;
61
-				$builder->add('facet_' . $facetType, FacetType::class, array(
62
-					'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label',
61
+				$builder->add('facet_'.$facetType, FacetType::class, array(
62
+					'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label',
63 63
 					'multiple' => true,
64 64
 					'expanded' => true,
65
-					'preferred_choices' => function ($val) use ($preferredChoices, $data, $facetType, $maxChoiceGroupCount, &$i) {
66
-						return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($data['facet_' . $facetType]) && in_array($val, $data['facet_' . $facetType]));
65
+					'preferred_choices' => function($val) use ($preferredChoices, $data, $facetType, $maxChoiceGroupCount, &$i) {
66
+						return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($data['facet_'.$facetType]) && in_array($val, $data['facet_'.$facetType]));
67 67
 					} 
68 68
 				));
69 69
 				unset($i);
70 70
 			}
71 71
 		}
72
-		if($result) {
73
-			$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options, $result) {
72
+		if ($result) {
73
+			$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($options, $result) {
74 74
 				$this->createFacets($event->getForm(), $result->getFacets(), $options, $event->getData());
75 75
 			});
76 76
 		}
@@ -107,16 +107,16 @@  discard block
 block discarded – undo
107 107
 		$preferredFilterChoices = $options['preferred_filter_choices'];
108 108
 		$maxChoiceGroupCount = $options['max_choice_group_count'];
109 109
 		$selectedFacets = $data->getFacets();
110
-		foreach($facets->getFacets() as $facetType => $facetValues) {
110
+		foreach ($facets->getFacets() as $facetType => $facetValues) {
111 111
 			$preferredChoices = isset($preferredFilterChoices[$facetType]) ? $preferredFilterChoices[$facetType] : array();
112 112
 			
113 113
 			$i = 0;
114
-			$builder->add('facet_' . $facetType, FacetType::class, array(
115
-				'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label',
114
+			$builder->add('facet_'.$facetType, FacetType::class, array(
115
+				'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label',
116 116
 				'multiple' => true,
117 117
 				'expanded' => true,
118 118
 				'choices' => $this->generateFacetChoices($facetType, $facetValues, isset($selectedFacets[$facetType]) ? $selectedFacets[$facetType] : array(), $options['facet_formatter']),
119
-				'preferred_choices' => function ($val) use ($preferredChoices, $selectedFacets, $facetType, $maxChoiceGroupCount, &$i) {
119
+				'preferred_choices' => function($val) use ($preferredChoices, $selectedFacets, $facetType, $maxChoiceGroupCount, &$i) {
120 120
 					return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($selectedFacets[$facetType]) && in_array($val, $selectedFacets[$facetType]));
121 121
 				} 
122 122
 			));
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
 	 */
132 132
 	protected function generateFacetChoices($facetType, array $facets, array $selectedFacets = array(), $formatter) {
133 133
 		$choices = array();
134
-		foreach($facets as $facet => $count) {
135
-			if($count == 0 && !in_array($facet, $selectedFacets))
134
+		foreach ($facets as $facet => $count) {
135
+			if ($count == 0 && !in_array($facet, $selectedFacets))
136 136
 				continue;
137 137
 			$choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet;
138 138
 		}
139
-		foreach($selectedFacets as $facet) {
139
+		foreach ($selectedFacets as $facet) {
140 140
 			$count = 0;
141 141
 			$choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet;
142 142
 		}
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	}
145 145
 	
146 146
 	protected function formatFacet($formatter, $facetType, $facet, $count) {
147
-		$default = $facet . ' (' . $count . ')';
148
-		if(!$formatter) {
147
+		$default = $facet.' ('.$count.')';
148
+		if (!$formatter) {
149 149
 			return $default;
150 150
 		}
151 151
 		return call_user_func($formatter, $facetType, $facet, $count, $default);
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -132,8 +132,9 @@
 block discarded – undo
132 132
 	protected function generateFacetChoices($facetType, array $facets, array $selectedFacets = array(), $formatter) {
133 133
 		$choices = array();
134 134
 		foreach($facets as $facet => $count) {
135
-			if($count == 0 && !in_array($facet, $selectedFacets))
136
-				continue;
135
+			if($count == 0 && !in_array($facet, $selectedFacets)) {
136
+							continue;
137
+			}
137 138
 			$choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet;
138 139
 		}
139 140
 		foreach($selectedFacets as $facet) {
Please login to merge, or discard this patch.