Passed
Push — master ( 85b490...1de0a7 )
by Darko
10:33
created
app/Services/Releases/ReleaseSearchService.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
             $maxAge, $excludedCats, $type, $cat, $minSize
71 71
         );
72 72
 
73
-        $whereSql = 'WHERE ' . implode(' AND ', $conditions);
73
+        $whereSql = 'WHERE '.implode(' AND ', $conditions);
74 74
         $orderBy = $this->getBrowseOrder($orderBy === '' ? 'posted_desc' : $orderBy);
75 75
 
76 76
         // Optimized query: direct query without subquery wrapper, filter on releases first using indexed columns
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
         );
103 103
 
104 104
         // Check cache
105
-        $cacheKey = md5($this->getCacheVersion() . $sql);
105
+        $cacheKey = md5($this->getCacheVersion().$sql);
106 106
         $releases = Cache::get($cacheKey);
107 107
         if ($releases !== null) {
108 108
             return $releases;
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
 
157 157
         // Size range conditions - uses indexed size column
158 158
         if (isset($sizeRange[$sizeFrom])) {
159
-            $conditions[] = sprintf('r.size > %d', (int)($sizeBase * $sizeRange[$sizeFrom]));
159
+            $conditions[] = sprintf('r.size > %d', (int) ($sizeBase * $sizeRange[$sizeFrom]));
160 160
         }
161 161
         if (isset($sizeRange[$sizeTo])) {
162
-            $conditions[] = sprintf('r.size < %d', (int)($sizeBase * $sizeRange[$sizeTo]));
162
+            $conditions[] = sprintf('r.size < %d', (int) ($sizeBase * $sizeRange[$sizeTo]));
163 163
         }
164 164
         if ($minSize > 0) {
165 165
             $conditions[] = sprintf('r.size >= %d', $minSize);
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
     private function getOptimizedCount(array $conditions): int
199 199
     {
200 200
         $maxResults = (int) config('nntmux.max_pager_results');
201
-        $whereSql = 'WHERE ' . implode(' AND ', $conditions);
202
-        $cacheKey = 'count_' . md5($whereSql);
201
+        $whereSql = 'WHERE '.implode(' AND ', $conditions);
202
+        $cacheKey = 'count_'.md5($whereSql);
203 203
 
204 204
         $count = Cache::get($cacheKey);
205 205
         if ($count !== null) {
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
                         'result' => $searchResult,
258 258
                     ]);
259 259
                 }
260
-                if (! empty($searchResult)) {
260
+                if (!empty($searchResult)) {
261 261
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
262 262
                 }
263 263
             }
@@ -295,15 +295,15 @@  discard block
 block discarded – undo
295 295
 
296 296
         $catQuery = Category::getCategorySearch($cat);
297 297
         $catQuery = preg_replace('/^(WHERE|AND)\s+/i', '', trim($catQuery));
298
-        if (! empty($catQuery) && $catQuery !== '1=1') {
298
+        if (!empty($catQuery) && $catQuery !== '1=1') {
299 299
             $conditions[] = $catQuery;
300 300
         }
301 301
 
302
-        if (! empty($excludedCats)) {
302
+        if (!empty($excludedCats)) {
303 303
             $conditions[] = sprintf('r.categories_id NOT IN (%s)', implode(',', array_map('intval', $excludedCats)));
304 304
         }
305 305
 
306
-        if (! empty($searchResult)) {
306
+        if (!empty($searchResult)) {
307 307
             $conditions[] = sprintf('r.id IN (%s)', implode(',', array_map('intval', $searchResult)));
308 308
         }
309 309
 
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
      */
365 365
     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
366 366
     {
367
-        $shouldCache = ! (isset($siteIdArr['id']) && (int) $siteIdArr['id'] > 0);
367
+        $shouldCache = !(isset($siteIdArr['id']) && (int) $siteIdArr['id'] > 0);
368 368
         $rawCacheKey = md5(serialize(func_get_args()).'tvSearch');
369 369
         $cacheKey = null;
370 370
         if ($shouldCache) {
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
         $episodeJoinCondition = '';
384 384
         $needsEpisodeJoin = false;
385 385
 
386
-        if (! empty($siteIdArr)) {
386
+        if (!empty($siteIdArr)) {
387 387
             $siteConditions = [];
388 388
             foreach ($siteIdArr as $column => $id) {
389 389
                 if ($id > 0) {
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
                 }
392 392
             }
393 393
 
394
-            if (! empty($siteConditions)) {
394
+            if (!empty($siteConditions)) {
395 395
                 $siteUsesVideoIdOnly = count($siteConditions) === 1 && isset($siteIdArr['id']) && (int) $siteIdArr['id'] > 0;
396 396
 
397 397
                 $seriesFilter = ($series !== '') ? sprintf('AND tve.series = %d', (int) preg_replace('/^s0*/i', '', $series)) : '';
@@ -415,12 +415,12 @@  discard block
 block discarded – undo
415 415
                 $videoIds = $results->pluck('video_id')->filter()->unique()->toArray();
416 416
                 $episodeIds = $results->pluck('episode_id')->filter()->unique()->toArray();
417 417
 
418
-                if (! empty($videoIds)) {
418
+                if (!empty($videoIds)) {
419 419
                     $conditions[] = sprintf('r.videos_id IN (%s)', implode(',', array_map('intval', $videoIds)));
420 420
                     $videoJoinCondition = sprintf('AND v.id IN (%s)', implode(',', array_map('intval', $videoIds)));
421 421
                 }
422 422
 
423
-                if (! empty($episodeIds) && ! $siteUsesVideoIdOnly) {
423
+                if (!empty($episodeIds) && !$siteUsesVideoIdOnly) {
424 424
                     $conditions[] = sprintf('r.tv_episodes_id IN (%s)', implode(',', array_map('intval', $episodeIds)));
425 425
                     $episodeJoinCondition = sprintf('AND tve.id IN (%s)', implode(',', array_map('intval', $episodeIds)));
426 426
                     $needsEpisodeJoin = true;
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
         }
434 434
 
435 435
         $searchResult = [];
436
-        if (! empty($name)) {
436
+        if (!empty($name)) {
437 437
             $searchName = $name;
438 438
             $hasValidSiteIds = false;
439 439
             foreach ($siteIdArr as $column => $id) {
@@ -443,18 +443,18 @@  discard block
 block discarded – undo
443 443
                 }
444 444
             }
445 445
 
446
-            if (! $hasValidSiteIds) {
447
-                if (! empty($series) && (int) $series < 1900) {
446
+            if (!$hasValidSiteIds) {
447
+                if (!empty($series) && (int) $series < 1900) {
448 448
                     $searchName .= sprintf(' S%s', str_pad($series, 2, '0', STR_PAD_LEFT));
449 449
                     $seriesNum = (int) preg_replace('/^s0*/i', '', $series);
450 450
                     $conditions[] = sprintf('tve.series = %d', $seriesNum);
451 451
                     $needsEpisodeJoin = true;
452
-                    if (! empty($episode) && ! str_contains($episode, '/')) {
452
+                    if (!empty($episode) && !str_contains($episode, '/')) {
453 453
                         $searchName .= sprintf('E%s', str_pad($episode, 2, '0', STR_PAD_LEFT));
454 454
                         $episodeNum = (int) preg_replace('/^e0*/i', '', $episode);
455 455
                         $conditions[] = sprintf('tve.episode = %d', $episodeNum);
456 456
                     }
457
-                } elseif (! empty($airDate)) {
457
+                } elseif (!empty($airDate)) {
458 458
                     $searchName .= ' '.str_replace(['/', '-', '.', '_'], ' ', $airDate);
459 459
                     $conditions[] = sprintf('DATE(tve.firstaired) = %s', escapeString($airDate));
460 460
                     $needsEpisodeJoin = true;
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
             // Fall back to Manticore if Elasticsearch didn't return results
470 470
             if (empty($searchResult)) {
471 471
                 $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $searchName, ['searchname']);
472
-                if (! empty($searchResult)) {
472
+                if (!empty($searchResult)) {
473 473
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
474 474
                 }
475 475
             }
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 
489 489
         $catQuery = Category::getCategorySearch($cat, 'tv');
490 490
         $catQuery = preg_replace('/^(WHERE|AND)\s+/i', '', trim($catQuery));
491
-        if (! empty($catQuery) && $catQuery !== '1=1') {
491
+        if (!empty($catQuery) && $catQuery !== '1=1') {
492 492
             $conditions[] = $catQuery;
493 493
         }
494 494
 
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
         if ($minSize > 0) {
499 499
             $conditions[] = sprintf('r.size >= %d', $minSize);
500 500
         }
501
-        if (! empty($excludedCategories)) {
501
+        if (!empty($excludedCategories)) {
502 502
             $conditions[] = sprintf('r.categories_id NOT IN (%s)', implode(',', array_map('intval', $excludedCategories)));
503 503
         }
504 504
 
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
         if ($releases->isNotEmpty()) {
541 541
             $countSql = sprintf(
542 542
                 'SELECT COUNT(*) as count FROM releases r %s %s %s',
543
-                (! empty($videoJoinCondition) ? 'LEFT JOIN videos v ON r.videos_id = v.id AND v.type = 0' : ''),
543
+                (!empty($videoJoinCondition) ? 'LEFT JOIN videos v ON r.videos_id = v.id AND v.type = 0' : ''),
544 544
                 ($needsEpisodeJoin ? sprintf('%s JOIN tv_episodes tve ON r.tv_episodes_id = tve.id %s', $joinType, $episodeJoinCondition) : ''),
545 545
                 $whereSql
546 546
             );
@@ -581,11 +581,11 @@  discard block
 block discarded – undo
581 581
             );
582 582
             $show = Release::fromQuery($showQry);
583 583
             if ($show->isNotEmpty()) {
584
-                if ((! empty($episode) && ! empty($series)) && $show[0]->episodes !== '') {
584
+                if ((!empty($episode) && !empty($series)) && $show[0]->episodes !== '') {
585 585
                     $showSql .= ' AND r.tv_episodes_id IN ('.$show[0]->episodes.') AND tve.series = '.$series;
586
-                } elseif (! empty($episode) && $show[0]->episodes !== '') {
586
+                } elseif (!empty($episode) && $show[0]->episodes !== '') {
587 587
                     $showSql = sprintf('AND r.tv_episodes_id IN (%s)', $show[0]->episodes);
588
-                } elseif (! empty($series) && empty($episode)) {
588
+                } elseif (!empty($series) && empty($episode)) {
589 589
                     $showSql .= ' AND r.tv_episodes_id IN ('.$show[0]->episodes.') AND tve.series = '.$series;
590 590
                 }
591 591
                 if ($show[0]->video > 0) {
@@ -595,21 +595,21 @@  discard block
 block discarded – undo
595 595
                 return [];
596 596
             }
597 597
         }
598
-        if (! empty($name) && $showSql === '') {
599
-            if (! empty($series) && (int) $series < 1900) {
598
+        if (!empty($name) && $showSql === '') {
599
+            if (!empty($series) && (int) $series < 1900) {
600 600
                 $name .= sprintf(' S%s', str_pad($series, 2, '0', STR_PAD_LEFT));
601
-                if (! empty($episode) && ! str_contains($episode, '/')) {
601
+                if (!empty($episode) && !str_contains($episode, '/')) {
602 602
                     $name .= sprintf('E%s', str_pad($episode, 2, '0', STR_PAD_LEFT));
603 603
                 }
604 604
                 if (empty($episode)) {
605 605
                     $name .= '*';
606 606
                 }
607
-            } elseif (! empty($airDate)) {
607
+            } elseif (!empty($airDate)) {
608 608
                 $name .= sprintf(' %s', str_replace(['/', '-', '.', '_'], ' ', $airDate));
609 609
             }
610 610
         }
611 611
         $searchResult = [];
612
-        if (! empty($name)) {
612
+        if (!empty($name)) {
613 613
             // Try Elasticsearch first if enabled
614 614
             if (config('nntmux.elasticsearch_enabled') === true) {
615 615
                 $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit);
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
             // Fall back to Manticore if Elasticsearch didn't return results
619 619
             if (empty($searchResult)) {
620 620
                 $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']);
621
-                if (! empty($searchResult)) {
621
+                if (!empty($searchResult)) {
622 622
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
623 623
                 }
624 624
             }
@@ -636,11 +636,11 @@  discard block
 block discarded – undo
636 636
             'WHERE r.passwordstatus %s %s %s %s %s %s %s',
637 637
             $this->showPasswords(),
638 638
             $showSql,
639
-            (! empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
639
+            (!empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
640 640
             Category::getCategorySearch($cat, 'tv'),
641 641
             ($maxAge > 0 ? sprintf('AND r.postdate > NOW() - INTERVAL %d DAY', $maxAge) : ''),
642 642
             ($minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : ''),
643
-            ! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : ''
643
+            !empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : ''
644 644
         );
645 645
         $baseSql = sprintf(
646 646
             "SELECT r.searchname, r.guid, r.postdate, r.categories_id, r.size, r.totalpart, r.fromname, r.passwordstatus, r.grabs, r.comments, r.adddate,
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
     public function animeSearch($aniDbID, int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, array $excludedCategories = []): mixed
682 682
     {
683 683
         $searchResult = [];
684
-        if (! empty($name)) {
684
+        if (!empty($name)) {
685 685
             // Try Elasticsearch first if enabled
686 686
             if (config('nntmux.elasticsearch_enabled') === true) {
687 687
                 $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit);
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
             // Fall back to Manticore if Elasticsearch didn't return results
691 691
             if (empty($searchResult)) {
692 692
                 $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']);
693
-                if (! empty($searchResult)) {
693
+                if (!empty($searchResult)) {
694 694
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
695 695
                 }
696 696
             }
@@ -710,8 +710,8 @@  discard block
 block discarded – undo
710 710
 			%s %s %s %s %s',
711 711
             $this->showPasswords(),
712 712
             ($aniDbID > -1 ? sprintf(' AND r.anidbid = %d ', $aniDbID) : ''),
713
-            (! empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
714
-            ! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : '',
713
+            (!empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
714
+            !empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : '',
715 715
             Category::getCategorySearch($cat),
716 716
             ($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '')
717 717
         );
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
     {
760 760
         // Early return if searching by name yields no results
761 761
         $searchResult = [];
762
-        if (! empty($name)) {
762
+        if (!empty($name)) {
763 763
             // Try Elasticsearch first if enabled
764 764
             if (config('nntmux.elasticsearch_enabled') === true) {
765 765
                 $searchResult = $this->elasticSearch->indexSearchTMA($name, $limit);
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
             // Fall back to Manticore if Elasticsearch didn't return results
769 769
             if (empty($searchResult)) {
770 770
                 $searchResult = $this->manticoreSearch->searchIndexes('releases_rt', $name, ['searchname']);
771
-                if (! empty($searchResult)) {
771
+                if (!empty($searchResult)) {
772 772
                     $searchResult = Arr::wrap(Arr::get($searchResult, 'id'));
773 773
                 }
774 774
             }
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
             sprintf('r.passwordstatus %s', $this->showPasswords()),
789 789
         ];
790 790
 
791
-        if (! empty($searchResult)) {
791
+        if (!empty($searchResult)) {
792 792
             $conditions[] = sprintf('r.id IN (%s)', implode(',', array_map('intval', $searchResult)));
793 793
         }
794 794
 
@@ -810,13 +810,13 @@  discard block
 block discarded – undo
810 810
             $conditions[] = sprintf('m.traktid = %d', $traktId);
811 811
         }
812 812
 
813
-        if (! empty($excludedCategories)) {
813
+        if (!empty($excludedCategories)) {
814 814
             $conditions[] = sprintf('r.categories_id NOT IN (%s)', implode(',', array_map('intval', $excludedCategories)));
815 815
         }
816 816
 
817 817
         $catQuery = Category::getCategorySearch($cat, 'movies');
818 818
         $catQuery = preg_replace('/^(WHERE|AND)\s+/i', '', trim($catQuery));
819
-        if (! empty($catQuery) && $catQuery !== '1=1') {
819
+        if (!empty($catQuery) && $catQuery !== '1=1') {
820 820
             $conditions[] = $catQuery;
821 821
         }
822 822
         if ($maxAge > 0) {
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
             }
893 893
 
894 894
             $results = $this->search(['searchname' => getSimilarName($name)], -1, '', '', -1, -1, 0, config('nntmux.items_per_page'), '', -1, $excludedCats, 'basic', [$parentCat]);
895
-            if (! $results) {
895
+            if (!$results) {
896 896
                 return $ret;
897 897
             }
898 898
 
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
     private function performIndexSearch(array $searchArr, int $limit): array
914 914
     {
915 915
         // Filter out -1 values and empty strings
916
-        $searchFields = Arr::where($searchArr, static function ($value) {
916
+        $searchFields = Arr::where($searchArr, static function($value) {
917 917
             return $value !== -1 && $value !== '' && $value !== null;
918 918
         });
919 919
 
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
                     foreach ($terms as $term) {
992 992
                         $term = trim($term);
993 993
                         if (strlen($term) >= 2) {
994
-                            $query->where($field, 'LIKE', '%' . $term . '%');
994
+                            $query->where($field, 'LIKE', '%'.$term.'%');
995 995
                         }
996 996
                     }
997 997
                 }
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 
1048 1048
         // Size conditions
1049 1049
         $sizeConditions = $this->buildSizeConditions($sizeFrom, $sizeTo);
1050
-        if (! empty($sizeConditions)) {
1050
+        if (!empty($sizeConditions)) {
1051 1051
             $conditions = array_merge($conditions, $sizeConditions);
1052 1052
         }
1053 1053
 
@@ -1057,7 +1057,7 @@  discard block
 block discarded – undo
1057 1057
 
1058 1058
         // Category conditions - only add if not empty
1059 1059
         $catQuery = $this->buildCategoryCondition($type, $cat);
1060
-        if (! empty($catQuery) && $catQuery !== '1=1') {
1060
+        if (!empty($catQuery) && $catQuery !== '1=1') {
1061 1061
             $conditions[] = $catQuery;
1062 1062
         }
1063 1063
 
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
         }
1072 1072
 
1073 1073
         // Excluded categories
1074
-        if (! empty($excludedCats)) {
1074
+        if (!empty($excludedCats)) {
1075 1075
             $excludedCatsClean = array_map('intval', $excludedCats);
1076 1076
             $conditions[] = sprintf('r.categories_id NOT IN (%s)', implode(',', $excludedCatsClean));
1077 1077
         }
Please login to merge, or discard this patch.
app/Services/Releases/ReleaseBrowseService.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
                 %s
198 198
             ORDER BY r.%s %s %s",
199 199
             $this->uSQL($userShows, 'videos_id'),
200
-            (! empty($excludedCats) ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''),
200
+            (!empty($excludedCats) ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''),
201 201
             Category::TV_ROOT,
202 202
             Category::TV_OTHER,
203 203
             $this->showPasswords(),
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
         $sql = '(1=2 ';
247 247
         foreach ($userQuery as $query) {
248 248
             $sql .= sprintf('OR (r.%s = %d', $type, $query->$type);
249
-            if (! empty($query->categories)) {
249
+            if (!empty($query->categories)) {
250 250
                 $catsArr = explode('|', $query->categories);
251 251
                 if (\count($catsArr) > 1) {
252 252
                     $sql .= sprintf(' AND r.categories_id IN (%s)', implode(',', $catsArr));
Please login to merge, or discard this patch.