Completed
Push — develop ( b4fba5...9773af )
by Kirill
12:38
created

AbstractCommand::findRoom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
/**
3
 * This file is part of GitterBot package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @date 26.01.2016 4:59
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace App\Console\Commands;
12
13
use Gitter\Client;
14
use React\EventLoop\Factory;
15
use Illuminate\Console\Command;
16
use React\EventLoop\LoopInterface;
17
use Illuminate\Contracts\Container\Container;
18
19
/**
20
 * Class AbstractCommand
21
 * @package App\Console\Commands
22
 */
23
abstract class AbstractCommand extends Command
24
{
25
    /**
26
     * @param Container $container
27
     * @param $token
28
     * @return Client
29
     */
30
    protected function createClient(Container $container, $token)
31
    {
32
        $loop       = Factory::create();
33
        $client     = new Client($loop, $token);
34
35
        // Bind container
36
        $container->singleton(LoopInterface::class, function() use ($loop)  { return $loop; });
37
        $container->singleton(Client::class, function() use ($client)       { return $client; });
38
39
        return $client;
40
    }
41
42
    /**
43
     * @param Client $client
44
     * @param string $roomId
45
     * @param \Closure $fulfilled
46
     * @return \React\Promise\PromiseInterface
47
     */
48
    public function findRoom(Client $client, string $roomId, \Closure $fulfilled)
49
    {
50
        return $client->getRoomByUri($roomId)
51
            ->then($fulfilled, function(\Throwable $exception) use ($roomId, $client, $fulfilled) {
0 ignored issues
show
Unused Code introduced by
The parameter $exception is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
                $client->getRoomById($roomId)->then($fulfilled, function(\Throwable $exception) {
0 ignored issues
show
Unused Code introduced by
The parameter $exception is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
                    $this->error(sprintf('Room "%s" not found.', $this->argument('room')));
54
                });
55
            });
56
    }
57
}