Passed
Push — master ( 03c468...179943 )
by Darko
11:56
created

GroupNameCategorizer::categorize()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 12
rs 8.0555
cc 9
nc 9
nop 1
1
<?php
2
namespace App\Services\Categorization\Categorizers;
3
use App\Models\Category;
4
use App\Services\Categorization\CategorizationResult;
5
use App\Services\Categorization\ReleaseContext;
6
class GroupNameCategorizer extends AbstractCategorizer
7
{
8
    protected int $priority = 5;
9
    public function getName(): string { return 'GroupName'; }
10
    public function categorize(ReleaseContext $context): CategorizationResult
11
    {
12
        $groupName = $context->groupName;
13
        if (empty($groupName)) return $this->noMatch();
14
        if (preg_match('/alt\.binaries\..*?(tv|hdtv|tvseries)/i', $groupName)) return $this->matched(Category::TV_OTHER, 0.6, 'group_tv');
15
        if (preg_match('/alt\.binaries\..*?(movies?|dvd|bluray|x264)/i', $groupName)) return $this->matched(Category::MOVIE_OTHER, 0.6, 'group_movie');
16
        if (preg_match('/alt\.binaries\..*?(erotica|pictures\.erotica|xxx)/i', $groupName)) return $this->matched(Category::XXX_OTHER, 0.7, 'group_xxx');
17
        if (preg_match('/alt\.binaries\..*?(sounds?|mp3|music|lossless)/i', $groupName)) return $this->matched(Category::MUSIC_OTHER, 0.6, 'group_music');
18
        if (preg_match('/alt\.binaries\..*?(games?|console|psx|nintendo)/i', $groupName)) return $this->matched(Category::GAME_OTHER, 0.6, 'group_game');
19
        if (preg_match('/alt\.binaries\..*?(warez|0day|apps?|software)/i', $groupName)) return $this->matched(Category::PC_0DAY, 0.6, 'group_pc');
20
        if (preg_match('/alt\.binaries\..*?(e-?book|ebook|comics?)/i', $groupName)) return $this->matched(Category::BOOKS_EBOOK, 0.6, 'group_book');
21
        return $this->noMatch();
22
    }
23
}
24