Completed
Push — master ( 9c9431...a1f3ed )
by Kirill
02:48
created

StartGitterBot::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 3 Features 1
Metric Value
c 5
b 3
f 1
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
1
<?php
2
3
/**
4
 * This file is part of GitterBot package.
5
 *
6
 * @author Serafim <[email protected]>
7
 * @date 24.09.2015 15:27
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace App\Console\Commands;
14
15
16
use App\Room;
17
use App\Gitter\Client;
18
use Carbon\Carbon;
19
use Illuminate\Console\Command;
20
use Illuminate\Contracts\Config\Repository;
21
use Illuminate\Contracts\Container\Container;
22
use Illuminate\Support\Facades\Log;
23
24
25
/**
26
 * Class StartGitterBot
27
 * @package App\Console\Commands
28
 */
29
class StartGitterBot extends Command
30
{
31
    /**
32
     * The name and signature of the console command.
33
     *
34
     * @var string
35
     */
36
    protected $signature = 'gitter:listen {room}';
37
38
39
    /**
40
     * The console command description.
41
     *
42
     * @var string
43
     */
44
    protected $description = 'Start gitter bot thread for target room.';
45
46
47
    /**
48
     * @var Container
49
     */
50
    protected $container;
51
52
    /**
53
     * @var string
54
     */
55
    protected $pid;
56
57
58
    /**
59
     * Execute the console command.
60
     *
61
     * @param Repository $config
62
     * @param Container $container
63
     *
64
     * @return mixed
65
     * @throws \InvalidArgumentException
66
     * @throws \RuntimeException
67
     * @throws \LogicException
68
     * @throws \Exception
69
     */
70
    public function handle(Repository $config, Container $container)
71
    {
72
        $client = Client::make($config->get('gitter.token'), $this->argument('room'));
73
        $stream = $container->make(Room::class)->listen();
0 ignored issues
show
Unused Code introduced by
$stream is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
74
75
        $this->info(sprintf('KarmaBot %s started at %s', Client::VERSION, Carbon::now()));
76
77
78
        $this->makePidFile();
79
        $client->run();
80
        $this->removePidFile();
81
    }
82
83
    /**
84
     * Create pid file
85
     */
86
    protected function makePidFile()
87
    {
88
        $this->pid = storage_path('pids/' . date('Y_m_d_tis_') . microtime(1) . '.pid');
89
        file_put_contents($this->pid, getmypid());
90
    }
91
92
    /**
93
     * Delete pid file
94
     */
95
    protected function removePidFile()
96
    {
97
        if (is_file($this->pid)) {
98
            unlink($this->pid);
99
        }
100
    }
101
}
102