Passed
Push — master ( 291b9a...710bcf )
by Darko
10:52
created
app/Services/Releases/ReleaseSearchService.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
                         'result' => $searchResult,
164 164
                     ]);
165 165
                 }
166
-                if (! empty($searchResult)) {
166
+                if (!empty($searchResult)) {
167 167
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
168 168
                 }
169 169
             }
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
 
202 202
         $catQuery = Category::getCategorySearch($cat);
203 203
         $catQuery = preg_replace('/^(WHERE|AND)\s+/i', '', trim($catQuery));
204
-        if (! empty($catQuery) && $catQuery !== '1=1') {
204
+        if (!empty($catQuery) && $catQuery !== '1=1') {
205 205
             $conditions[] = $catQuery;
206 206
         }
207 207
 
208
-        if (! empty($excludedCats)) {
208
+        if (!empty($excludedCats)) {
209 209
             $conditions[] = sprintf('r.categories_id NOT IN (%s)', implode(',', array_map('intval', $excludedCats)));
210 210
         }
211 211
 
212
-        if (! empty($searchResult)) {
212
+        if (!empty($searchResult)) {
213 213
             $conditions[] = sprintf('r.id IN (%s)', implode(',', array_map('intval', $searchResult)));
214 214
         }
215 215
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
      */
271 271
     public function tvSearch(array $siteIdArr = [], string $series = '', string $episode = '', string $airDate = '', int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, int $minSize = 0, array $excludedCategories = []): mixed
272 272
     {
273
-        $shouldCache = ! (isset($siteIdArr['id']) && (int) $siteIdArr['id'] > 0);
273
+        $shouldCache = !(isset($siteIdArr['id']) && (int) $siteIdArr['id'] > 0);
274 274
         $rawCacheKey = md5(serialize(func_get_args()).'tvSearch');
275 275
         $cacheKey = null;
276 276
         if ($shouldCache) {
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
         $episodeJoinCondition = '';
290 290
         $needsEpisodeJoin = false;
291 291
 
292
-        if (! empty($siteIdArr)) {
292
+        if (!empty($siteIdArr)) {
293 293
             $siteConditions = [];
294 294
             foreach ($siteIdArr as $column => $id) {
295 295
                 if ($id > 0) {
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                 }
298 298
             }
299 299
 
300
-            if (! empty($siteConditions)) {
300
+            if (!empty($siteConditions)) {
301 301
                 $siteUsesVideoIdOnly = count($siteConditions) === 1 && isset($siteIdArr['id']) && (int) $siteIdArr['id'] > 0;
302 302
 
303 303
                 $seriesFilter = ($series !== '') ? sprintf('AND tve.series = %d', (int) preg_replace('/^s0*/i', '', $series)) : '';
@@ -321,12 +321,12 @@  discard block
 block discarded – undo
321 321
                 $videoIds = $results->pluck('video_id')->filter()->unique()->toArray();
322 322
                 $episodeIds = $results->pluck('episode_id')->filter()->unique()->toArray();
323 323
 
324
-                if (! empty($videoIds)) {
324
+                if (!empty($videoIds)) {
325 325
                     $conditions[] = sprintf('r.videos_id IN (%s)', implode(',', array_map('intval', $videoIds)));
326 326
                     $videoJoinCondition = sprintf('AND v.id IN (%s)', implode(',', array_map('intval', $videoIds)));
327 327
                 }
328 328
 
329
-                if (! empty($episodeIds) && ! $siteUsesVideoIdOnly) {
329
+                if (!empty($episodeIds) && !$siteUsesVideoIdOnly) {
330 330
                     $conditions[] = sprintf('r.tv_episodes_id IN (%s)', implode(',', array_map('intval', $episodeIds)));
331 331
                     $episodeJoinCondition = sprintf('AND tve.id IN (%s)', implode(',', array_map('intval', $episodeIds)));
332 332
                     $needsEpisodeJoin = true;
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
         }
340 340
 
341 341
         $searchResult = [];
342
-        if (! empty($name)) {
342
+        if (!empty($name)) {
343 343
             $searchName = $name;
344 344
             $hasValidSiteIds = false;
345 345
             foreach ($siteIdArr as $column => $id) {
@@ -349,18 +349,18 @@  discard block
 block discarded – undo
349 349
                 }
350 350
             }
351 351
 
352
-            if (! $hasValidSiteIds) {
353
-                if (! empty($series) && (int) $series < 1900) {
352
+            if (!$hasValidSiteIds) {
353
+                if (!empty($series) && (int) $series < 1900) {
354 354
                     $searchName .= sprintf(' S%s', str_pad($series, 2, '0', STR_PAD_LEFT));
355 355
                     $seriesNum = (int) preg_replace('/^s0*/i', '', $series);
356 356
                     $conditions[] = sprintf('tve.series = %d', $seriesNum);
357 357
                     $needsEpisodeJoin = true;
358
-                    if (! empty($episode) && ! str_contains($episode, '/')) {
358
+                    if (!empty($episode) && !str_contains($episode, '/')) {
359 359
                         $searchName .= sprintf('E%s', str_pad($episode, 2, '0', STR_PAD_LEFT));
360 360
                         $episodeNum = (int) preg_replace('/^e0*/i', '', $episode);
361 361
                         $conditions[] = sprintf('tve.episode = %d', $episodeNum);
362 362
                     }
363
-                } elseif (! empty($airDate)) {
363
+                } elseif (!empty($airDate)) {
364 364
                     $searchName .= ' '.str_replace(['/', '-', '.', '_'], ' ', $airDate);
365 365
                     $conditions[] = sprintf('DATE(tve.firstaired) = %s', escapeString($airDate));
366 366
                     $needsEpisodeJoin = true;
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
             // Fall back to Manticore if Elasticsearch didn't return results
376 376
             if (empty($searchResult)) {
377 377
                 $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $searchName, ['searchname']);
378
-                if (! empty($searchResult)) {
378
+                if (!empty($searchResult)) {
379 379
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
380 380
                 }
381 381
             }
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 
395 395
         $catQuery = Category::getCategorySearch($cat, 'tv');
396 396
         $catQuery = preg_replace('/^(WHERE|AND)\s+/i', '', trim($catQuery));
397
-        if (! empty($catQuery) && $catQuery !== '1=1') {
397
+        if (!empty($catQuery) && $catQuery !== '1=1') {
398 398
             $conditions[] = $catQuery;
399 399
         }
400 400
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
         if ($minSize > 0) {
405 405
             $conditions[] = sprintf('r.size >= %d', $minSize);
406 406
         }
407
-        if (! empty($excludedCategories)) {
407
+        if (!empty($excludedCategories)) {
408 408
             $conditions[] = sprintf('r.categories_id NOT IN (%s)', implode(',', array_map('intval', $excludedCategories)));
409 409
         }
410 410
 
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
         if ($releases->isNotEmpty()) {
447 447
             $countSql = sprintf(
448 448
                 'SELECT COUNT(*) as count FROM releases r %s %s %s',
449
-                (! empty($videoJoinCondition) ? 'LEFT JOIN videos v ON r.videos_id = v.id AND v.type = 0' : ''),
449
+                (!empty($videoJoinCondition) ? 'LEFT JOIN videos v ON r.videos_id = v.id AND v.type = 0' : ''),
450 450
                 ($needsEpisodeJoin ? sprintf('%s JOIN tv_episodes tve ON r.tv_episodes_id = tve.id %s', $joinType, $episodeJoinCondition) : ''),
451 451
                 $whereSql
452 452
             );
@@ -487,11 +487,11 @@  discard block
 block discarded – undo
487 487
             );
488 488
             $show = Release::fromQuery($showQry);
489 489
             if ($show->isNotEmpty()) {
490
-                if ((! empty($episode) && ! empty($series)) && $show[0]->episodes !== '') {
490
+                if ((!empty($episode) && !empty($series)) && $show[0]->episodes !== '') {
491 491
                     $showSql .= ' AND r.tv_episodes_id IN ('.$show[0]->episodes.') AND tve.series = '.$series;
492
-                } elseif (! empty($episode) && $show[0]->episodes !== '') {
492
+                } elseif (!empty($episode) && $show[0]->episodes !== '') {
493 493
                     $showSql = sprintf('AND r.tv_episodes_id IN (%s)', $show[0]->episodes);
494
-                } elseif (! empty($series) && empty($episode)) {
494
+                } elseif (!empty($series) && empty($episode)) {
495 495
                     $showSql .= ' AND r.tv_episodes_id IN ('.$show[0]->episodes.') AND tve.series = '.$series;
496 496
                 }
497 497
                 if ($show[0]->video > 0) {
@@ -501,21 +501,21 @@  discard block
 block discarded – undo
501 501
                 return [];
502 502
             }
503 503
         }
504
-        if (! empty($name) && $showSql === '') {
505
-            if (! empty($series) && (int) $series < 1900) {
504
+        if (!empty($name) && $showSql === '') {
505
+            if (!empty($series) && (int) $series < 1900) {
506 506
                 $name .= sprintf(' S%s', str_pad($series, 2, '0', STR_PAD_LEFT));
507
-                if (! empty($episode) && ! str_contains($episode, '/')) {
507
+                if (!empty($episode) && !str_contains($episode, '/')) {
508 508
                     $name .= sprintf('E%s', str_pad($episode, 2, '0', STR_PAD_LEFT));
509 509
                 }
510 510
                 if (empty($episode)) {
511 511
                     $name .= '*';
512 512
                 }
513
-            } elseif (! empty($airDate)) {
513
+            } elseif (!empty($airDate)) {
514 514
                 $name .= sprintf(' %s', str_replace(['/', '-', '.', '_'], ' ', $airDate));
515 515
             }
516 516
         }
517 517
         $searchResult = [];
518
-        if (! empty($name)) {
518
+        if (!empty($name)) {
519 519
             // Try Elasticsearch first if enabled
520 520
             if (config('nntmux.elasticsearch_enabled') === true) {
521 521
                 $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit);
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
             // Fall back to Manticore if Elasticsearch didn't return results
525 525
             if (empty($searchResult)) {
526 526
                 $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']);
527
-                if (! empty($searchResult)) {
527
+                if (!empty($searchResult)) {
528 528
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
529 529
                 }
530 530
             }
@@ -542,11 +542,11 @@  discard block
 block discarded – undo
542 542
             'WHERE r.passwordstatus %s %s %s %s %s %s %s',
543 543
             $this->showPasswords(),
544 544
             $showSql,
545
-            (! empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
545
+            (!empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
546 546
             Category::getCategorySearch($cat, 'tv'),
547 547
             ($maxAge > 0 ? sprintf('AND r.postdate > NOW() - INTERVAL %d DAY', $maxAge) : ''),
548 548
             ($minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : ''),
549
-            ! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : ''
549
+            !empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : ''
550 550
         );
551 551
         $baseSql = sprintf(
552 552
             "SELECT r.searchname, r.guid, r.postdate, r.categories_id, r.size, r.totalpart, r.fromname, r.passwordstatus, r.grabs, r.comments, r.adddate,
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
     public function animeSearch($aniDbID, int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, array $excludedCategories = []): mixed
588 588
     {
589 589
         $searchResult = [];
590
-        if (! empty($name)) {
590
+        if (!empty($name)) {
591 591
             // Try Elasticsearch first if enabled
592 592
             if (config('nntmux.elasticsearch_enabled') === true) {
593 593
                 $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit);
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
             // Fall back to Manticore if Elasticsearch didn't return results
597 597
             if (empty($searchResult)) {
598 598
                 $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']);
599
-                if (! empty($searchResult)) {
599
+                if (!empty($searchResult)) {
600 600
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
601 601
                 }
602 602
             }
@@ -616,8 +616,8 @@  discard block
 block discarded – undo
616 616
 			%s %s %s %s %s',
617 617
             $this->showPasswords(),
618 618
             ($aniDbID > -1 ? sprintf(' AND r.anidbid = %d ', $aniDbID) : ''),
619
-            (! empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
620
-            ! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : '',
619
+            (!empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
620
+            !empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : '',
621 621
             Category::getCategorySearch($cat),
622 622
             ($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '')
623 623
         );
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
     {
666 666
         // Early return if searching by name yields no results
667 667
         $searchResult = [];
668
-        if (! empty($name)) {
668
+        if (!empty($name)) {
669 669
             // Try Elasticsearch first if enabled
670 670
             if (config('nntmux.elasticsearch_enabled') === true) {
671 671
                 $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit);
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
             // Fall back to Manticore if Elasticsearch didn't return results
675 675
             if (empty($searchResult)) {
676 676
                 $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']);
677
-                if (! empty($searchResult)) {
677
+                if (!empty($searchResult)) {
678 678
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
679 679
                 }
680 680
             }
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
             sprintf('r.passwordstatus %s', $this->showPasswords()),
695 695
         ];
696 696
 
697
-        if (! empty($searchResult)) {
697
+        if (!empty($searchResult)) {
698 698
             $conditions[] = sprintf('r.id IN (%s)', implode(',', array_map('intval', $searchResult)));
699 699
         }
700 700
 
@@ -716,13 +716,13 @@  discard block
 block discarded – undo
716 716
             $conditions[] = sprintf('m.traktid = %d', $traktId);
717 717
         }
718 718
 
719
-        if (! empty($excludedCategories)) {
719
+        if (!empty($excludedCategories)) {
720 720
             $conditions[] = sprintf('r.categories_id NOT IN (%s)', implode(',', array_map('intval', $excludedCategories)));
721 721
         }
722 722
 
723 723
         $catQuery = Category::getCategorySearch($cat, 'movies');
724 724
         $catQuery = preg_replace('/^(WHERE|AND)\s+/i', '', trim($catQuery));
725
-        if (! empty($catQuery) && $catQuery !== '1=1') {
725
+        if (!empty($catQuery) && $catQuery !== '1=1') {
726 726
             $conditions[] = $catQuery;
727 727
         }
728 728
         if ($maxAge > 0) {
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
             }
799 799
 
800 800
             $results = $this->search(['searchname' => getSimilarName($name)], -1, '', '', -1, -1, 0, config('nntmux.items_per_page'), '', -1, $excludedCats, 'basic', [$parentCat]);
801
-            if (! $results) {
801
+            if (!$results) {
802 802
                 return $ret;
803 803
             }
804 804
 
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
     private function performIndexSearch(array $searchArr, int $limit): array
820 820
     {
821 821
         // Filter out -1 values and empty strings
822
-        $searchFields = Arr::where($searchArr, static function ($value) {
822
+        $searchFields = Arr::where($searchArr, static function($value) {
823 823
             return $value !== -1 && $value !== '' && $value !== null;
824 824
         });
825 825
 
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
                     foreach ($terms as $term) {
898 898
                         $term = trim($term);
899 899
                         if (strlen($term) >= 2) {
900
-                            $query->where($field, 'LIKE', '%' . $term . '%');
900
+                            $query->where($field, 'LIKE', '%'.$term.'%');
901 901
                         }
902 902
                     }
903 903
                 }
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
 
954 954
         // Size conditions
955 955
         $sizeConditions = $this->buildSizeConditions($sizeFrom, $sizeTo);
956
-        if (! empty($sizeConditions)) {
956
+        if (!empty($sizeConditions)) {
957 957
             $conditions = array_merge($conditions, $sizeConditions);
958 958
         }
959 959
 
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
 
964 964
         // Category conditions - only add if not empty
965 965
         $catQuery = $this->buildCategoryCondition($type, $cat);
966
-        if (! empty($catQuery) && $catQuery !== '1=1') {
966
+        if (!empty($catQuery) && $catQuery !== '1=1') {
967 967
             $conditions[] = $catQuery;
968 968
         }
969 969
 
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
         }
978 978
 
979 979
         // Excluded categories
980
-        if (! empty($excludedCats)) {
980
+        if (!empty($excludedCats)) {
981 981
             $excludedCatsClean = array_map('intval', $excludedCats);
982 982
             $conditions[] = sprintf('r.categories_id NOT IN (%s)', implode(',', $excludedCatsClean));
983 983
         }
Please login to merge, or discard this patch.