Completed
Push — master ( e98ea9...145cbe )
by Frank
59:38
created

ChannelCommand::processChannelCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 9.4285
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
11
namespace T3Bot\Commands;
12
13
use T3Bot\Slack\Message;
14
15
/**
16
 * Class ChannelCommand.
17
 */
18
class ChannelCommand extends AbstractCommand
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $commandName = 'channel';
24
25
    /**
26
     * @var array
27
     */
28
    protected $helpCommands = [
29
        'help' => 'shows this help'
30
    ];
31
32
    /**
33
     * @return bool|string
34
     *
35
     * @throws \Doctrine\DBAL\DBALException
36
     */
37
    public function process()
38
    {
39
        return false;
40
    }
41
42
    /**
43
     * @param array $data
44
     * @example $data:
45
     * [
46
     *  "type": "channel_created",
47
     *  "channel": {
48
     *      "id": "C024BE91L",
49
     *      "name": "fun",
50
     *      "created": 1360782804,
51
     *      "creator": "U024BE7LH"
52
     *  }
53
     * ]
54
     */
55
    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...
56
    {
57
        $channel = $data['channel'];
58
        $message = new Message();
59
        $message->setText(sprintf(
60
            '<@%s> open channel #%s, join it <#%s>',
61
            $channel['creator'],
62
            $channel['name'],
63
            $channel['id']
64
        ));
65
        $this->sendResponse($message, null, $GLOBALS['config']['slack']['channels']['channelCreated']);
66
    }
67
}
68