GameManager   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 13

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 13
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A resetGame() 0 23 2
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;
10
11
use pocketmine\entity\Effect;
12
use pocketmine\entity\EffectInstance;
13
use pocketmine\Player;
14
use pocketmine\Server;
15
use VectorNetworkProject\TheMix\event\GameEventListener;
16
use VectorNetworkProject\TheMix\game\corepvp\CoreManager;
17
use VectorNetworkProject\TheMix\game\corepvp\PhaseManager;
18
use VectorNetworkProject\TheMix\game\corepvp\TeamManager;
19
use VectorNetworkProject\TheMix\task\PhaseTask;
20
use VectorNetworkProject\TheMix\TheMix;
21
22
class GameManager
0 ignored issues
show
Coding Style introduced by
GameManager 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...
23
{
24
    public static function resetGame(): void
25
    {
26
        TeamManager::resetTeam();
27
        CoreManager::resetHP();
28
        GameEventListener::setFinish(false);
29
        PhaseManager::setPhase(1);
30
        PhaseTask::setTime();
31
        foreach (Server::getInstance()->getOnlinePlayers() as $player) {
32
            $player->teleport(Server::getInstance()->getDefaultLevel()->getSpawnLocation());
33
            $player->setGamemode(Player::ADVENTURE);
34
            $player->setNameTag($player->getName());
35
            $player->setDisplayName($player->getName());
36
            $player->setFood(20);
37
            $player->setHealth(20);
38
            $player->setMaxHealth(20);
39
            $player->getInventory()->clearAll();
40
            $player->getArmorInventory()->clearAll();
41
            $player->removeAllEffects();
42
            $player->addEffect(new EffectInstance(Effect::getEffect(Effect::NIGHT_VISION), 99999999 * 20, 11, false));
0 ignored issues
show
Bug introduced by
It seems like \pocketmine\entity\Effec...y\Effect::NIGHT_VISION) can be null; however, __construct() 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...
43
        }
44
        TheMix::getInstance()->getServer()->unloadLevel(TheMix::getInstance()->getServer()->getLevelByName(DefaultConfig::getStageLevelName()));
45
        TheMix::getInstance()->getServer()->loadLevel(DefaultConfig::getStageLevelName());
46
    }
47
}
48