Completed
Push — master ( 1f1d6f...d17677 )
by De Cramer
9s
created

ChatCommandDataProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
ccs 4
cts 4
cp 1
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace eXpansion\Core\DataProviders;
4
5
use eXpansion\Core\Model\Helpers\ChatNotificationInterface;
6
use eXpansion\Core\Services\ChatCommands;
7
8
class ChatCommandDataProvider extends AbstractDataProvider
9
{
10
    /** @var ChatCommands  */
11
    protected $chatCommands;
12
13
    /** @var ChatCommands  */
14
    protected $chatNotification;
15
16
    /**
17
     * ChatCommandDataProvider constructor.
18
     * @param $chatCommands
19
     */
20 7
    public function __construct(ChatCommands $chatCommands, ChatNotificationInterface $chatNotification)
21
    {
22 7
        $this->chatCommands = $chatCommands;
23 7
        $this->chatNotification = $chatNotification;
0 ignored issues
show
Documentation Bug introduced by
It seems like $chatNotification of type object<eXpansion\Core\Mo...tNotificationInterface> is incompatible with the declared type object<eXpansion\Core\Services\ChatCommands> of property $chatNotification.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24 7
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29 1
    public function registerPlugin($pluginId, $pluginService)
30
    {
31 1
        parent::registerPlugin($pluginId, $pluginService);
32
33 1
        $this->chatCommands->registerPlugin($pluginId, $pluginService);
34 1
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39 1
    public function deletePlugin($pluginId)
40
    {
41 1
        parent::deletePlugin($pluginId);
42
43 1
        $this->chatCommands->deletePlugin($pluginId);
44 1
    }
45
46
    /**
47
     * Called when a player chats on the server.
48
     *
49
     * @param int $playerUid
50
     * @param string $login
51
     * @param string $text
52
     * @param bool $isRegisteredCmd
53
     */
54 4
    public function onPlayerChat($playerUid, $login, $text, $isRegisteredCmd = false)
1 ignored issue
show
Unused Code introduced by
The parameter $playerUid 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...
55
    {
56 4
        if (!$isRegisteredCmd) {
57 1
            return;
58
        }
59
60 3
        $cmdAndArgs = explode(' ', $text, 2);
61 3
        $cmdTxt = substr($cmdAndArgs[0], 1);
62 3
        $parameter = count($cmdAndArgs) > 1 ? $cmdAndArgs[1] : '';
63
64
        // Internal dedicated serer command to ignore.
65 3
        if($cmdTxt === 'version') {
66 1
            return;
67
        }
68
69 2
        $command = $this->chatCommands->getChatCommand($cmdTxt);
70 2
        if ($command && $command->validate($login, $parameter)) {
71 1
            $command->execute($login, $command->parseParameters($parameter));
72
        } else {
73 1
            $this->chatNotification->sendMessage('expansion_core.chat_commands.wrong_chat', $login);
0 ignored issues
show
Bug introduced by
The method sendMessage() does not seem to exist on object<eXpansion\Core\Services\ChatCommands>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
74
        }
75
    }
76
}