Passed
Branch develop (8534ca)
by Aleksandr
03:12
created

CoreCommandWrapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace AlexCool\Rcon\Command\Wrapper\Minecraft;
4
5
use AlexCool\Rcon\Client\MinecraftClient;
6
use AlexCool\Rcon\Command\Wrapper\AbstractCommandWrapper;
7
use AlexCool\Rcon\Utils\CommandFormatter;
8
9
/**
10
 * @package AlexCool\Rcon\Command\Wrapper\Minecraft
11
 */
12
class CoreCommandWrapper extends AbstractCommandWrapper
13
{
14
    /**
15
     * Command list
16
     */
17
    const HELP_COMMAND = 'help';
18
19
    /**
20
     * @var MinecraftClient
21
     */
22
    protected $client;
23
24
    /**
25
     * @var CommandFormatter
26
     */
27
    protected $commandFormatter;
28
29
    /**
30
     * @param MinecraftClient $client
31
     * @param CommandFormatter $commandFormatter
32
     */
33
    public function __construct(MinecraftClient $client, CommandFormatter $commandFormatter)
34
    {
35
        $this->client = $client;
36
        $this->commandFormatter = $commandFormatter;
37
    }
38
39
    /**
40
     * Shows a list of server or plugin commands in the console or in-game.
41
     *
42
     * @param string|null $topic
43
     * @param int|null $pageNumber
44
     *
45
     * @return bool|mixed
46
     */
47
    public function help(string $topic = null, int $pageNumber = null)
48
    {
49
        $this->commandFormatter->addElement('%s', self::HELP_COMMAND);
50
51
        if ($topic) {
52
            $this->commandFormatter->addElement('%s', $topic);
53
        }
54
55
        if ($pageNumber) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $pageNumber of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
56
            $this->commandFormatter->addElement('%u', $pageNumber);
57
        }
58
59
        return $this->sendCommand($this->commandFormatter->compile());
60
    }
61
}
62