Passed
Push — master ( 6b3709...d172f1 )
by Darko
10:26
created

IrcScraperCommand::handle()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 29
rs 9.1111
cc 6
nc 10
nop 0
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Blacklight\IRCScraper;
6
use Illuminate\Console\Command;
7
8
class IrcScraperCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'irc:scrape
16
                            {--debug : Turn on debug (shows sent/received messages from the socket)}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Scrape IRC for PRE information';
24
25
    /**
26
     * Execute the console command.
27
     */
28
    public function handle(): int
29
    {
30
        if (config('irc_settings.scrape_irc_username') === '') {
31
            $this->error('ERROR! You must put a username in config/irc_settings.php');
32
33
            return self::FAILURE;
34
        }
35
36
        // Use Laravel's built-in quiet mode for silent operation
37
        $silent = $this->option('quiet');
38
        $debug = $this->option('debug');
39
40
        if (! $silent) {
41
            $this->info('Starting IRC Scraper...');
42
            if ($debug) {
43
                $this->warn('Debug mode enabled');
44
            }
45
        }
46
47
        try {
48
            new IRCScraper($silent, $debug);
49
50
            return self::SUCCESS;
51
        } catch (\Exception $e) {
52
            if (! $silent) {
53
                $this->error($e->getMessage());
54
            }
55
56
            return self::FAILURE;
57
        }
58
    }
59
}
60