Completed
Pull Request — master (#37)
by De Cramer
08:24
created

BasicEmote   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 46
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A execute() 0 8 1
1
<?php
2
3
namespace eXpansion\Bundle\Emotes\ChatCommand;
4
5
use eXpansion\Core\Helpers\ChatNotification;
6
use eXpansion\Core\Model\ChatCommand\AbstractChatCommand;
7
use eXpansion\Core\Storage\PlayerStorage;
8
9
10
/**
11
 * Class BasicEmote to handle basic emote chat oommands.
12
 *
13
 * @package eXpansion\Bundle\Emotes\ChatCommand;
14
 * @author oliver de Cramer <[email protected]>
15
 */
16
class BasicEmote extends AbstractChatCommand
17
{
18
    /** @var string[] */
19
    protected $messages;
20
21
    /** @var ChatNotification  */
22
    protected $chatNotification;
23
24
    /** @var PlayerStorage */
25
    protected $playerStorage;
26
27
    /**
28
     * BasicEmote constructor.
29
     *
30
     * @param string $command The chat command
31
     * @param string $message The emote message to send
0 ignored issues
show
Documentation introduced by
There is no parameter named $message. Did you maybe mean $nbMessages?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
32
     * @param ChatNotification $chatNotification
33
     * @param array $aliases
34
     * @param bool $parametersAsArray
35
     */
36
    public function __construct(
37
        $command,
38
        $nbMessages,
39
        array $aliases = [],
40
        ChatNotification $chatNotification,
41
        PlayerStorage $playerStorage,
42
        $parametersAsArray = true
43
    ) {
44
        parent::__construct($command, $aliases, $parametersAsArray);
45
        $this->chatNotification = $chatNotification;
46
        $this->playerStorage = $playerStorage;
47
48
        for($i = 1; $i <= $nbMessages; $i++) {
49
            $this->messages[] = "expansion_emotes.$command" . $i;
50
        }
51
    }
52
53
    public function execute($login, $parameter)
54
    {
55
        $select = rand(0, count($this->messages) - 1);
56
        $message = $this->messages[$select];
57
58
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
59
        $this->chatNotification->sendMessage($message, null, ['%nickname%' => $nickName]);
60
    }
61
}