Passed
Push — master ( c4af72...5193cc )
by Nicolaas
09:52 queued 06:38
created
src/Helpers/FindEditableObjects.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
             return (string) $dataObject->{$validMethod};
178 178
         }
179 179
 
180
-        if (! in_array($dataObject->ClassName, $this->excludedClasses, true)) {
180
+        if (!in_array($dataObject->ClassName, $this->excludedClasses, true)) {
181 181
             if (empty($this->cache[$type][$dataObject->ClassName]) || true !== $this->cache[$type][$dataObject->ClassName]) {
182 182
                 foreach ($validMethods as $validMethod) {
183 183
                     $outcome = null;
184 184
                     if ($dataObject->hasMethod($validMethod)) {
185 185
                         $outcome = $dataObject->{$validMethod}();
186
-                    } elseif (! empty($dataObject->{$validMethod})) {
186
+                    } elseif (!empty($dataObject->{$validMethod})) {
187 187
                         $outcome = $dataObject->{$validMethod};
188 188
                     }
189 189
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
                 continue;
216 216
             }
217 217
 
218
-            if (! isset($this->relationTypesCovered[$relType])) {
218
+            if (!isset($this->relationTypesCovered[$relType])) {
219 219
                 $rels = $dataObject->{$relationName}();
220 220
                 if ($rels) {
221 221
                     if ($rels instanceof DataList) {
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 
243 243
     protected function getRelations($dataObject): array
244 244
     {
245
-        if (! isset($this->cache['rels'][$dataObject->ClassName])) {
245
+        if (!isset($this->cache['rels'][$dataObject->ClassName])) {
246 246
             $this->cache['rels'][$dataObject->ClassName] = array_merge(
247 247
                 Config::inst()->get($dataObject->ClassName, 'belongs_to'),
248 248
                 Config::inst()->get($dataObject->ClassName, 'has_one'),
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
                 Config::inst()->get($dataObject->ClassName, 'many_many')
252 252
             );
253 253
             foreach ($this->cache['rels'][$dataObject->ClassName] as $key => $value) {
254
-                if (! in_array($value, $this->excludedClasses, true)) {
254
+                if (!in_array($value, $this->excludedClasses, true)) {
255 255
                     unset($this->cache['rels'][$dataObject->ClassName][$key]);
256 256
                 }
257 257
             }
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 
263 263
     protected function getValidMethods(string $type): array
264 264
     {
265
-        if (! isset($this->cache['validMethods'][$type])) {
265
+        if (!isset($this->cache['validMethods'][$type])) {
266 266
             $this->cache['validMethods'][$type] = $this->Config()->get($type);
267 267
         }
268 268
 
Please login to merge, or discard this patch.
src/Api/SearchApi.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -209,23 +209,23 @@  discard block
 block discarded – undo
209 209
         $this->initCache();
210 210
         $count = 0;
211 211
         // we should have these already.
212
-        foreach($this->objects as $item) {
213
-            if($item->canEdit()) {
212
+        foreach ($this->objects as $item) {
213
+            if ($item->canEdit()) {
214 214
                 $fields = $this->getAllValidFields($item->ClassName);
215 215
                 foreach ($fields as $field) {
216 216
                     $new = str_replace($word, $replace, $item->$field);
217
-                    if($new !== $item->$field) {
217
+                    if ($new !== $item->$field) {
218 218
                         $count++;
219 219
                         $item->$field = $new;
220 220
                         $isPublished = false;
221
-                        if($item->hasMethod('isPublished')) {
221
+                        if ($item->hasMethod('isPublished')) {
222 222
                             $isPublished = $item->isPublished();
223 223
                         }
224 224
                         $item->write();
225
-                        if($isPublished) {
225
+                        if ($isPublished) {
226 226
                             $item->publishRecursive();
227 227
                         }
228
-                        if ($this->debug) { DB::alteration_message('<h2>Match:  '.$item->ClassName.$item->ID.'</h2>'.$new.'<hr />');}
228
+                        if ($this->debug) { DB::alteration_message('<h2>Match:  ' . $item->ClassName . $item->ID . '</h2>' . $new . '<hr />'); }
229 229
                     }
230 230
                 }
231 231
             }
@@ -236,48 +236,48 @@  discard block
 block discarded – undo
236 236
 
237 237
     protected function getMatches(string $word = ''): array
238 238
     {
239
-        if ($this->debug) {$startOuter = microtime(true);}
239
+        if ($this->debug) {$startOuter = microtime(true); }
240 240
 
241 241
         $this->workOutExclusions();
242 242
         $this->workOutWords($word);
243 243
 
244
-        if ($this->debug) {DB::alteration_message('Words searched for ' . implode(', ', $this->words));}
244
+        if ($this->debug) {DB::alteration_message('Words searched for ' . implode(', ', $this->words)); }
245 245
         $array = [];
246 246
 
247 247
         if (count($this->words)) {
248 248
             foreach ($this->getAllDataObjects() as $className) {
249
-                if ($this->debug) {DB::alteration_message(' ... Searching in ' . $className);}
250
-                if (! in_array($className, $this->excludedClasses, true)) {
249
+                if ($this->debug) {DB::alteration_message(' ... Searching in ' . $className); }
250
+                if (!in_array($className, $this->excludedClasses, true)) {
251 251
                     $array[$className] = [];
252 252
                     $fields = $this->getAllValidFields($className);
253 253
                     $filterAny = [];
254 254
                     foreach ($fields as $field) {
255
-                        if (! in_array($field, $this->excludedFields, true)) {
256
-                            if ($this->debug) {DB::alteration_message(' ... ... Searching in ' . $className . '.' . $field);}
255
+                        if (!in_array($field, $this->excludedFields, true)) {
256
+                            if ($this->debug) {DB::alteration_message(' ... ... Searching in ' . $className . '.' . $field); }
257 257
                             $filterAny[$field . ':PartialMatch'] = $this->words;
258 258
                         }
259 259
                     }
260 260
 
261 261
                     if ([] !== $filterAny) {
262
-                        if ($this->debug) {$startInner = microtime(true); DB::alteration_message(' ... Filter: ' . implode(', ', array_keys($filterAny)));}
262
+                        if ($this->debug) {$startInner = microtime(true); DB::alteration_message(' ... Filter: ' . implode(', ', array_keys($filterAny))); }
263 263
                         $array[$className] = $className::get()
264 264
                             ->filterAny($filterAny)
265 265
                             ->limit($this->Config()->get('limit_of_count_per_data_object'))
266 266
                             ->column('ID')
267 267
                         ;
268
-                        if ($this->debug) {$elaps = microtime(true) - $startInner;DB::alteration_message('search for ' . $className . ' taken : ' . $elaps);}
268
+                        if ($this->debug) {$elaps = microtime(true) - $startInner; DB::alteration_message('search for ' . $className . ' taken : ' . $elaps); }
269 269
                     }
270 270
 
271
-                    if ($this->debug) {DB::alteration_message(' ... No fields in ' . $className);}
271
+                    if ($this->debug) {DB::alteration_message(' ... No fields in ' . $className); }
272 272
                 }
273 273
 
274
-                if ($this->debug) {DB::alteration_message(' ... Skipping ' . $className);}
274
+                if ($this->debug) {DB::alteration_message(' ... Skipping ' . $className); }
275 275
             }
276 276
         } else {
277 277
             $array = $this->getDefaultList();
278 278
         }
279 279
 
280
-        if ($this->debug) {$elaps = microtime(true) - $startOuter;DB::alteration_message('seconds taken find results: ' . $elaps);}
280
+        if ($this->debug) {$elaps = microtime(true) - $startOuter; DB::alteration_message('seconds taken find results: ' . $elaps); }
281 281
         return $array;
282 282
     }
283 283
 
@@ -286,14 +286,14 @@  discard block
 block discarded – undo
286 286
         $back = $this->config()->get('hours_back_for_recent') ?? 24;
287 287
         $limit = $this->Config()->get('limit_per_class_for_recent') ?? 5;
288 288
         $threshold = strtotime('-' . $back . ' hours', DBDatetime::now()->getTimestamp());
289
-        if (! $threshold) {
289
+        if (!$threshold) {
290 290
             $threshold = time() - 86400;
291 291
         }
292 292
 
293 293
         $array = [];
294 294
         $classNames = $this->getAllDataObjects();
295 295
         foreach ($classNames as $className) {
296
-            if (! in_array($className, $this->excludedClasses, true)) {
296
+            if (!in_array($className, $this->excludedClasses, true)) {
297 297
                 $array[$className] = $className::get()
298 298
                     ->filter('LastEdited:GreaterThan', date('Y-m-d H:i:s', $threshold))
299 299
                     ->sort('LastEdited', 'DESC')
@@ -308,14 +308,14 @@  discard block
 block discarded – undo
308 308
 
309 309
     protected function turnArrayIntoObjects(array $matches, ?int $limit = 0) : array
310 310
     {
311
-        if(empty($this->objects)) {
312
-            if(! $limit) {
311
+        if (empty($this->objects)) {
312
+            if (!$limit) {
313 313
                 $limit = $this->Config()->get('limit_of_count_per_data_object');
314 314
             }
315 315
             $this->objects = [];
316
-            if ($this->debug) {DB::alteration_message('number of classes: ' . count($matches));}
316
+            if ($this->debug) {DB::alteration_message('number of classes: ' . count($matches)); }
317 317
             foreach ($matches as $className => $ids) {
318
-                if ($this->debug) {$start = microtime(true);DB::alteration_message(' ... number of matches for : ' . $className . ': ' . count($ids));}
318
+                if ($this->debug) {$start = microtime(true); DB::alteration_message(' ... number of matches for : ' . $className . ': ' . count($ids)); }
319 319
                 if (count($ids)) {
320 320
                     $className = (string) $className;
321 321
                     $items = $className::get()
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                         }
329 329
                     }
330 330
                 }
331
-                if ($this->debug) {$elaps = microtime(true) - $start;DB::alteration_message('seconds taken to find objects in: ' . $className . ': ' . $elaps);}
331
+                if ($this->debug) {$elaps = microtime(true) - $start; DB::alteration_message('seconds taken to find objects in: ' . $className . ': ' . $elaps); }
332 332
             }
333 333
         }
334 334
 
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
         $finder = Injector::inst()->get(FindEditableObjects::class);
344 344
         $finder->initCache();
345 345
         $items = $this->turnArrayIntoObjects($matches);
346
-        foreach($items as $item) {
346
+        foreach ($items as $item) {
347 347
             $link = $finder->getLink($item, $this->excludedClasses);
348 348
             $cmsEditLink = '';
349 349
             if ($item->canEdit()) {
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
             $testWords = array_unique($testWords);
393 393
             foreach ($testWords as $wordKey => $word) {
394 394
                 //match a exact field to full words / one word
395
-                $fullWords = ! (bool) $wordKey;
395
+                $fullWords = !(bool) $wordKey;
396 396
                 if (false === $done) {
397 397
                     $count = 0;
398 398
                     foreach ($fieldValues as $fieldValue) {
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
             $this->words[] = $word;
465 465
         }
466 466
 
467
-        if (! count($this->words)) {
467
+        if (!count($this->words)) {
468 468
             user_error('No word has been provided');
469 469
         }
470 470
 
@@ -477,8 +477,8 @@  discard block
 block discarded – undo
477 477
 
478 478
     protected function getAllDataObjects(): array
479 479
     {
480
-        if ($this->debug) {DB::alteration_message('Base Class: ' . $this->baseClass);}
481
-        if (! isset($this->cache['AllDataObjects'][$this->baseClass])) {
480
+        if ($this->debug) {DB::alteration_message('Base Class: ' . $this->baseClass); }
481
+        if (!isset($this->cache['AllDataObjects'][$this->baseClass])) {
482 482
             $this->cache['AllDataObjects'][$this->baseClass] = array_values(
483 483
                 ClassInfo::subclassesFor($this->baseClass, false)
484 484
             );
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 
491 491
     protected function getAllValidFields(string $className): array
492 492
     {
493
-        if (! isset($this->cache['AllValidFields'][$className])) {
493
+        if (!isset($this->cache['AllValidFields'][$className])) {
494 494
             $array = [];
495 495
             $fullList = Config::inst()->get($className, 'db');
496 496
             if (is_array($fullList)) {
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 
517 517
     protected function getIndexedFields(string $className, array $dbFields): array
518 518
     {
519
-        if (! isset($this->cache['IndexedFields'][$className])) {
519
+        if (!isset($this->cache['IndexedFields'][$className])) {
520 520
             $this->cache['IndexedFields'][$className] = [];
521 521
             $indexes = Config::inst()->get($className, 'indexes');
522 522
             if (is_array($indexes)) {
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 
552 552
     protected function isValidFieldType(string $className, string $fieldName, string $type): bool
553 553
     {
554
-        if (! isset($this->cache['ValidFieldTypes'][$type])) {
554
+        if (!isset($this->cache['ValidFieldTypes'][$type])) {
555 555
             $this->cache['ValidFieldTypes'][$type] = false;
556 556
             $singleton = Injector::inst()->get($className);
557 557
             $field = $singleton->dbObject($fieldName);
Please login to merge, or discard this patch.
src/Admin/SearchAdmin.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             (new CheckboxField('QuickSearch', 'Search Main Fields Only', $this->isQuickSearch))
60 60
                 ->setDescription('This is faster but only searches a limited number of fields')
61 61
         );
62
-        if (! $this->getRequest()->requestVar('Keywords')) {
62
+        if (!$this->getRequest()->requestVar('Keywords')) {
63 63
             $resultsTitle = 'Recently Edited';
64 64
             $this->listHTML = $this->renderWith(self::class . '_Results');
65 65
         } else {
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
 
120 120
     public function SearchResults(): ?ArrayList
121 121
     {
122
-        $this->isQuickSearch = ! empty($this->rawData['QuickSearch']);
122
+        $this->isQuickSearch = !empty($this->rawData['QuickSearch']);
123 123
         $this->keywords = trim($this->rawData['Keywords'] ?? '');
124 124
         $this->replace = trim($this->rawData['ReplaceWith'] ?? '');
125
-        if($this->replace) {
125
+        if ($this->replace) {
126 126
             return Injector::inst()->get(SearchApi ::class)
127 127
                 ->setBaseClass(DataObject::class)
128 128
                 ->setIsQuickSearch(false)
Please login to merge, or discard this patch.
src/Tasks/SiteWideSearch.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
         Environment::increaseMemoryLimitTo(-1);
36 36
         $debug = $request->postVar('debug') ? 'checked="checked"' : '';
37 37
         $word = Convert::raw2sql($request->requestVar('word'));
38
-        if (! is_string($word)) {
38
+        if (!is_string($word)) {
39 39
             $word = '';
40 40
         }
41 41
         $replace = Convert::raw2sql($request->requestVar('replace'));
42
-        if (! is_string($replace)) {
42
+        if (!is_string($replace)) {
43 43
             $replace = '';
44 44
         }
45 45
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
                 DB::alteration_message($cmsEditLink . $title, 'obsolete');
80 80
             }
81 81
         }
82
-        if($replace) {
82
+        if ($replace) {
83 83
             $api->doReplacement($word, $replace);
84 84
             $api->setDebug(true);
85 85
         }
Please login to merge, or discard this patch.