Streak   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 57
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A addStreak() 0 8 2
A getStreak() 0 6 2
A resetStreak() 0 4 1
A unsetStreak() 0 6 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\streak;
10
11
use pocketmine\Player;
12
use VectorNetworkProject\TheMix\game\event\player\PlayerStreakEvent;
13
14
class Streak
0 ignored issues
show
Coding Style introduced by
Streak 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...
15
{
16
    /** @var array $streaks */
17
    private static $streaks;
18
19
    /**
20
     * @param Player $player
21
     */
22
    public static function init(Player $player): void
23
    {
24
        self::$streaks[$player->getXuid()] = 0;
25
    }
26
27
    /**
28
     * @param Player $player
29
     *
30
     * @throws \ReflectionException
31
     */
32
    public static function addStreak(Player $player): void
33
    {
34
        $event = new PlayerStreakEvent($player, self::getStreak($player) + 1);
35
        $event->call();
36
        if (!$event->isCancelled()) {
37
            self::$streaks[$player->getXuid()] += 1;
38
        }
39
    }
40
41
    /**
42
     * @param Player $player
43
     *
44
     * @return int
45
     */
46
    public static function getStreak(Player $player): int
47
    {
48
        return isset(self::$streaks[$player->getXuid()])
49
            ? self::$streaks[$player->getXuid()]
50
            : 0;
51
    }
52
53
    /**
54
     * @param Player $player
55
     */
56
    public static function resetStreak(Player $player): void
57
    {
58
        self::$streaks[$player->getXuid()] = 0;
59
    }
60
61
    /**
62
     * @param Player $player
63
     */
64
    public static function unsetStreak(Player $player): void
65
    {
66
        if (isset(self::$streaks[$player->getXuid()])) {
67
            unset(self::$streaks[$player->getXuid()]);
68
        }
69
    }
70
}
71