Completed
Push — master ( 191869...afc708 )
by Frank
08:08
created

ChannelCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * T3Bot.
4
 *
5
 * @author Frank Nägler <[email protected]>
6
 *
7
 * @link http://www.t3bot.de
8
 * @link http://wiki.typo3.org/T3Bot
9
 */
10
namespace T3Bot\Commands;
11
12
use Slack\Payload;
13
use Slack\RealTimeClient;
14
use T3Bot\Slack\Message;
15
16
/**
17
 * Class ChannelCommand.
18
 *
19
 * @property string commandName
20
 * @property array helpCommands
21
 */
22
class ChannelCommand extends AbstractCommand
23
{
24
    /**
25
     * AbstractCommand constructor.
26
     *
27
     * @param Payload        $payload
28
     * @param RealTimeClient $client
29
     */
30 View Code Duplication
    public function __construct(Payload $payload, RealTimeClient $client)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        $this->commandName = 'channel';
33
        $this->helpCommands = [
34
            'help' => 'shows this help'
35
        ];
36
        parent::__construct($payload, $client);
37
    }
38
39
    /**
40
     * @return bool|string
41
     *
42
     * @throws \Doctrine\DBAL\DBALException
43
     */
44
    public function process()
45
    {
46
        return false;
47
    }
48
49
    /**
50
     * @param array $data
51
     * @example $data:
52
     * [
53
     *  "type": "channel_created",
54
     *  "channel": {
55
     *      "id": "C024BE91L",
56
     *      "name": "fun",
57
     *      "created": 1360782804,
58
     *      "creator": "U024BE7LH"
59
     *  }
60
     * ]
61
     */
62
    public function processChannelCreated(array $data)
0 ignored issues
show
Coding Style introduced by
processChannelCreated uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
63
    {
64
        $channel = $data['channel'];
65
        $message = new Message();
66
        $message->setText(sprintf(
67
            '<@%s> opened channel #%s, join it <#%s>',
68
            $channel['creator'],
69
            $channel['name'],
70
            $channel['id']
71
        ));
72
        $this->sendResponse($message, null, $GLOBALS['config']['slack']['channels']['channelCreated']);
73
    }
74
}
75