Completed
Push — dev2 ( 983df6...5a7fe0 )
by Gordon
14:04
created
code/ElasticaUtil.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -96,20 +96,20 @@  discard block
 block discarded – undo
96 96
 					//Need to check capitalisation of terms suggested that are different
97 97
 
98 98
 					$chr = mb_substr ($possiblyUppercase, 0, 1, "UTF-8");
99
-    				if (mb_strtolower($chr, "UTF-8") != $chr) {
100
-    					$upperLowercaseWord = $lowercaseWord;
101
-    					$upperLowercaseWord[0] = $chr;
102
-    					$withHighlights = str_replace($lowercaseWord, $upperLowercaseWord, $possiblyUppercaseHighlighted);
103
-    					$lowercaseWord[0] = $chr;
104
-    					array_push($plain, $lowercaseWord);
105
-    					array_push($highlighted, $withHighlights);
106
-    				} else {
107
-    					//No need to capitalise, so add suggested word
108
-    					array_push($plain, $lowercaseWord);
109
-
110
-    					//No need to capitalise, so add suggested highlighted word
111
-    					array_push($highlighted, $possiblyUppercaseHighlighted);
112
-    				}
99
+					if (mb_strtolower($chr, "UTF-8") != $chr) {
100
+						$upperLowercaseWord = $lowercaseWord;
101
+						$upperLowercaseWord[0] = $chr;
102
+						$withHighlights = str_replace($lowercaseWord, $upperLowercaseWord, $possiblyUppercaseHighlighted);
103
+						$lowercaseWord[0] = $chr;
104
+						array_push($plain, $lowercaseWord);
105
+						array_push($highlighted, $withHighlights);
106
+					} else {
107
+						//No need to capitalise, so add suggested word
108
+						array_push($plain, $lowercaseWord);
109
+
110
+						//No need to capitalise, so add suggested highlighted word
111
+						array_push($highlighted, $possiblyUppercaseHighlighted);
112
+					}
113 113
 				}
114 114
 			}
115 115
 
@@ -140,38 +140,38 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	public static function parseSuggestionExplanation($explanation) {
142 142
 		$explanation = explode('-ConstantScore', $explanation)[0];
143
-        $bracketPos = strpos($explanation, ')~');
143
+		$bracketPos = strpos($explanation, ')~');
144 144
 
145
-        if (substr($explanation, 0,2) == '((') {
146
-        	$explanation = substr($explanation, 2, $bracketPos-2);
147
-        } elseif (substr($explanation, 0,1) == '(') {
148
-        	$explanation = substr($explanation, 1, $bracketPos-2);
149
-        }
145
+		if (substr($explanation, 0,2) == '((') {
146
+			$explanation = substr($explanation, 2, $bracketPos-2);
147
+		} elseif (substr($explanation, 0,1) == '(') {
148
+			$explanation = substr($explanation, 1, $bracketPos-2);
149
+		}
150 150
 
151
-       	$terms = array();
151
+	   	$terms = array();
152 152
 
153
-        //Field name(s) => terms
154
-        $splits = explode(' ', $explanation);
153
+		//Field name(s) => terms
154
+		$splits = explode(' ', $explanation);
155 155
 
156
-        foreach ($splits as $fieldAndTerm) {
157
-        	$splits = explode(':', $fieldAndTerm);
156
+		foreach ($splits as $fieldAndTerm) {
157
+			$splits = explode(':', $fieldAndTerm);
158 158
 
159
-        	// This is the no terms case
160
-        	if (sizeof($splits) < 2) {
161
-        		break;
162
-        	}
159
+			// This is the no terms case
160
+			if (sizeof($splits) < 2) {
161
+				break;
162
+			}
163 163
 
164
-        	$fieldname = $splits[0];
165
-        	$term = $splits[1];
164
+			$fieldname = $splits[0];
165
+			$term = $splits[1];
166 166
 
167
-        	if (!isset($terms[$fieldname])) {
168
-        		$terms[$fieldname] = array();
169
-        	}
167
+			if (!isset($terms[$fieldname])) {
168
+				$terms[$fieldname] = array();
169
+			}
170 170
 
171
-        	array_push($terms[$fieldname], $term);
172
-        }
171
+			array_push($terms[$fieldname], $term);
172
+		}
173 173
 
174
-        return $terms;
174
+		return $terms;
175 175
 	}
176 176
 
177 177
 	/**
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 * @var string $content Text to display when in command line mode
29 29
 	 */
30 30
 	public static function message($content) {
31
-		if (\Director::is_cli() && self::$cli_printer_output === true) {
31
+		if(\Director::is_cli() && self::$cli_printer_output === true) {
32 32
 			echo "$content\n";
33 33
 		}
34 34
 	}
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 		$options = $alternativeQuerySuggestions[0]['options'];
54 54
 
55 55
 		$resultArray = null;
56
-		if (sizeof($options) > 0) {
56
+		if(sizeof($options) > 0) {
57 57
 			//take the first suggestion
58 58
 			$suggestedPhrase = $options[0]['text'];
59 59
 			$suggestedPhraseHighlighted = $options[0]['highlighted'];
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 			$originalParts = explode(' ', $originalQuery);
63 63
 			$suggestedParts = explode(' ', $suggestedPhrase);
64 64
 
65
-			$markedHighlightedParts = ' '.$suggestedPhraseHighlighted.' ';
66
-			$markedHighlightedParts = str_replace(' '.$preTags, ' '.self::$pre_marker, $markedHighlightedParts);
65
+			$markedHighlightedParts = ' ' . $suggestedPhraseHighlighted . ' ';
66
+			$markedHighlightedParts = str_replace(' ' . $preTags, ' ' . self::$pre_marker, $markedHighlightedParts);
67 67
 
68
-			$markedHighlightedParts = str_replace($postTags.' ', self::$post_marker, $markedHighlightedParts);
68
+			$markedHighlightedParts = str_replace($postTags . ' ', self::$post_marker, $markedHighlightedParts);
69 69
 
70 70
 			$markedHighlightedParts = trim($markedHighlightedParts);
71 71
 			$markedHighlightedParts = trim($markedHighlightedParts);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 			$lowerToUpper = array();
77 77
 			$lowerToHighlighted = array();
78 78
 			$ctr = 0;
79
-			foreach ($suggestedParts as $lowercaseWord) {
79
+			foreach($suggestedParts as $lowercaseWord) {
80 80
 				$lowerToUpper[$lowercaseWord] = $originalParts[$ctr];
81 81
 				$lowerToHighlighted[$lowercaseWord] = $highlightedParts[$ctr];
82 82
 				$ctr++;
@@ -84,19 +84,19 @@  discard block
 block discarded – undo
84 84
 
85 85
 			$plain = array();
86 86
 			$highlighted = array();
87
-			foreach ($suggestedParts as $lowercaseWord) {
87
+			foreach($suggestedParts as $lowercaseWord) {
88 88
 				$possiblyUppercase = $lowerToUpper[$lowercaseWord];
89 89
 				$possiblyUppercaseHighlighted = $lowerToHighlighted[$lowercaseWord];
90 90
 
91 91
 				//If the terms are identical other than case, e.g. new => New, then simply swap
92
-				if (strtolower($possiblyUppercase) == $lowercaseWord) {
92
+				if(strtolower($possiblyUppercase) == $lowercaseWord) {
93 93
 					array_push($plain, $possiblyUppercase);
94 94
 					array_push($highlighted, $possiblyUppercase);
95 95
 				} else {
96 96
 					//Need to check capitalisation of terms suggested that are different
97 97
 
98
-					$chr = mb_substr ($possiblyUppercase, 0, 1, "UTF-8");
99
-    				if (mb_strtolower($chr, "UTF-8") != $chr) {
98
+					$chr = mb_substr($possiblyUppercase, 0, 1, "UTF-8");
99
+    				if(mb_strtolower($chr, "UTF-8") != $chr) {
100 100
     					$upperLowercaseWord = $lowercaseWord;
101 101
     					$upperLowercaseWord[0] = $chr;
102 102
     					$withHighlights = str_replace($lowercaseWord, $upperLowercaseWord, $possiblyUppercaseHighlighted);
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 				}
114 114
 			}
115 115
 
116
-			$highlighted = ' '.implode(' ', $highlighted).' ';
117
-			$highlighted = str_replace(self::$pre_marker, ' '.$preTags, $highlighted);
118
-			$highlighted = str_replace(self::$post_marker, $postTags.' ', $highlighted);
116
+			$highlighted = ' ' . implode(' ', $highlighted) . ' ';
117
+			$highlighted = str_replace(self::$pre_marker, ' ' . $preTags, $highlighted);
118
+			$highlighted = str_replace(self::$post_marker, $postTags . ' ', $highlighted);
119 119
 
120 120
 			$resultArray['suggestedQuery'] = implode(' ', $plain);
121 121
 			$resultArray['suggestedQueryHighlighted'] = trim($highlighted);
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
 		$explanation = explode('-ConstantScore', $explanation)[0];
143 143
         $bracketPos = strpos($explanation, ')~');
144 144
 
145
-        if (substr($explanation, 0,2) == '((') {
146
-        	$explanation = substr($explanation, 2, $bracketPos-2);
147
-        } elseif (substr($explanation, 0,1) == '(') {
148
-        	$explanation = substr($explanation, 1, $bracketPos-2);
145
+        if(substr($explanation, 0, 2) == '((') {
146
+        	$explanation = substr($explanation, 2, $bracketPos - 2);
147
+        } elseif(substr($explanation, 0, 1) == '(') {
148
+        	$explanation = substr($explanation, 1, $bracketPos - 2);
149 149
         }
150 150
 
151 151
        	$terms = array();
@@ -153,18 +153,18 @@  discard block
 block discarded – undo
153 153
         //Field name(s) => terms
154 154
         $splits = explode(' ', $explanation);
155 155
 
156
-        foreach ($splits as $fieldAndTerm) {
156
+        foreach($splits as $fieldAndTerm) {
157 157
         	$splits = explode(':', $fieldAndTerm);
158 158
 
159 159
         	// This is the no terms case
160
-        	if (sizeof($splits) < 2) {
160
+        	if(sizeof($splits) < 2) {
161 161
         		break;
162 162
         	}
163 163
 
164 164
         	$fieldname = $splits[0];
165 165
         	$term = $splits[1];
166 166
 
167
-        	if (!isset($terms[$fieldname])) {
167
+        	if(!isset($terms[$fieldname])) {
168 168
         		$terms[$fieldname] = array();
169 169
         	}
170 170
 
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 	 * @return function print content to either web browser or command line.  Can be optionally supressed
192 192
 	 */
193 193
 	public static function getPrinter() {
194
-		return function ($content) {
195
-			if (self::$cli_printer_output === true) {
194
+		return function($content) {
195
+			if(self::$cli_printer_output === true) {
196 196
 				print(\Director::is_cli() ? "T1 $content\n" : "T2 <p>$content</p>");
197 197
 			}
198 198
 
Please login to merge, or discard this patch.