TeamManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 55
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A JoinTeam() 0 21 4
A resetTeam() 0 5 1
addList() 0 1 ?
removeList() 0 1 ?
isJoined() 0 1 ?
getList() 0 1 ?
1
<?php
2
/**
3
 * Copyright (c) 2018 VectorNetworkProject. All rights reserved. MIT license.
4
 *
5
 * GitHub: https://github.com/VectorNetworkProject/TheMix
6
 * Website: https://www.vector-network.tk
7
 */
8
9
namespace VectorNetworkProject\TheMix\game\corepvp;
10
11
use pocketmine\Player;
12
use VectorNetworkProject\TheMix\game\corepvp\blue\BlueSpawnManager;
13
use VectorNetworkProject\TheMix\game\corepvp\blue\BlueTeamManager;
14
use VectorNetworkProject\TheMix\game\corepvp\red\RedSpawnManager;
15
use VectorNetworkProject\TheMix\game\corepvp\red\RedTeamManager;
16
use VectorNetworkProject\TheMix\game\kit\BlueKit;
17
use VectorNetworkProject\TheMix\game\kit\RedKit;
18
19
abstract class TeamManager
0 ignored issues
show
Coding Style introduced by
TeamManager does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
20
{
21
    /**
22
     * @param Player $player
23
     */
24
    public static function JoinTeam(Player $player)
0 ignored issues
show
Coding Style introduced by
function JoinTeam() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
25
    {
26
        if (BlueTeamManager::isJoined($player) || RedTeamManager::isJoined($player)) {
27
            return;
28
        }
29
        if (BlueTeamManager::getListCount() < RedTeamManager::getListCount()) {
30
            BlueTeamManager::addList($player);
31
            BlueKit::sendItems($player);
32
            $player->teleport(BlueSpawnManager::getRandomPosition());
0 ignored issues
show
Bug introduced by
It seems like \VectorNetworkProject\Th...er::getRandomPosition() can be null; however, teleport() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
33
            $player->setNameTag("§b{$player->getName()}§r");
34
            $player->setDisplayName("§b{$player->getName()}§r");
35
            $player->sendMessage('§bBLUE§fに入りました。');
36
        } else {
37
            RedTeamManager::addList($player);
38
            RedKit::sendItem($player);
39
            $player->teleport(RedSpawnManager::getRandomPosition());
0 ignored issues
show
Bug introduced by
It seems like \VectorNetworkProject\Th...er::getRandomPosition() can be null; however, teleport() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
40
            $player->setNameTag("§c{$player->getName()}§r");
41
            $player->setDisplayName("§c{$player->getName()}§r");
42
            $player->sendMessage('§cRED§fに入りました。');
43
        }
44
    }
45
46
    public static function resetTeam(): void
47
    {
48
        RedTeamManager::ClearList();
49
        BlueTeamManager::ClearList();
50
    }
51
52
    /**
53
     * @param Player $player
54
     */
55
    abstract public static function addList(Player $player): void;
56
57
    /**
58
     * @param Player $player
59
     */
60
    abstract public static function removeList(Player $player): void;
61
62
    /**
63
     * @param Player $player
64
     *
65
     * @return bool
66
     */
67
    abstract public static function isJoined(Player $player): bool;
68
69
    /**
70
     * @return array
71
     */
72
    abstract public static function getList(): array;
73
}
74