Completed
Pull Request — master (#165)
by
unknown
02:58
created

Connect::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace eXpansion\Bundle\Acme\ChatCommand;
4
5
use eXpansion\Bundle\Acme\Plugins\Test;
6
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups;
7
use eXpansion\Framework\AdminGroups\Model\AbstractAdminChatCommand;
8
use eXpansion\Framework\Core\Storage\PlayerStorage;
9
use Maniaplanet\DedicatedServer\Connection;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
13
/**
14
 * Class Records
15
 *
16
 * @package eXpansion\Bundle\Admin\ChatCommand;
17
 * @author  reaby
18
 */
19
class Connect extends AbstractAdminChatCommand
20
{
21
    /**
22
     * @var Connection
23
     */
24
    private $connection;
25
    /**
26
     * @var Test
27
     */
28
    private $testPlugin;
29
    /**
30
     * @var PlayerStorage
31
     */
32
    private $playerStorage;
33
34
    /**
35
     * ScriptPanel constructor.
36
     *
37
     * @param                      $command
38
     * @param                      $permission
39
     * @param array                $aliases
40
     * @param Connection           $connection
41
     * @param AdminGroups          $adminGroups
42
     * @param Test                 $testPlugin
43
     * @param PlayerStorage        $playerStorage
44
     */
45
    public function __construct(
46
        $command,
47
        $permission,
48
        array $aliases = [],
49
        Connection $connection,
50
        AdminGroups $adminGroups,
51
        Test $testPlugin,
52
        PlayerStorage $playerStorage
53
    ) {
54
        parent::__construct($command, $permission, $aliases, $adminGroups);
55
56
        $this->connection = $connection;
57
        $this->testPlugin = $testPlugin;
58
        $this->playerStorage = $playerStorage;
59
    }
60
61
    public function configure()
62
    {
63
        parent::configure();
64
        $this->inputDefinition->addArgument(
65
            new InputArgument('count', InputArgument::REQUIRED, "count of fake players to connect")
66
        );
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function execute($login, InputInterface $input)
73
    {
74
        $count = $input->getArgument("count");
75
        $online = count($this->playerStorage->getOnline());
76
        if ($online <= $count) {
77
            $this->testPlugin->connectQueue = $count - $online;
0 ignored issues
show
Documentation Bug introduced by
It seems like $count - $online can also be of type double. However, the property $connectQueue is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
78
        }
79
    }
80
}
81