Dual   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A register() 0 4 1
A unregister() 0 4 1
A get() 0 4 1
A add() 0 4 1
A addKill() 0 4 1
A addDeath() 0 4 1
A addWin() 0 4 1
A addLose() 0 4 1
A getRankingByWin() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: UramnOIL
5
 * Date: 2018/10/07
6
 * Time: 0:50
7
 */
8
9
namespace VectorNetworkProject\DataProvider\Tables\Dual;
10
11
use pocketmine\IPlayer;
12
use VectorNetworkProject\DataProvider\Tables\TableBase;
13
14
class Dual extends TableBase
15
{
16
	public const INIT			= 'userdataprovider.duel.init';
17
	public const REGISTER		= 'userdataprovider.duel.register';
18
	public const UNREGISTER		= 'userdataprovider.duel.unregister';
19
	public const GET			= 'userdataprovider.duel.get';
20
	public const ADD_COUNT		= 'userdataprovider.duel.addcount';
21
	public const GET_RANKING	= 'userdataprovider.duel.getrankingbywin';
22
23
	public function init(): void
24
	{
25
		$this->connector->executeGeneric(self::INIT);
26
	}
27
28
	/**
29
	 * 	プレイヤーを登録します
30
	 *
31
	 * @param IPlayer $player
32
	 * @param callable $onInserted
33
	 * @param callable|null $onError
34
	 */
35
	public function register(IPlayer $player, callable $onInserted, ?callable $onError = null): void
36
	{
37
		$this->connector->executeInsert(self::REGISTER, [$player->getName()], $onInserted, $onError);
38
	}
39
40
	/**
41
	 * プレイヤーを登録解除します
42
	 *
43
	 * @param IPlayer $player
44
	 * @param callable|null $onSelect
45
	 * @param callable|null $onError
46
	 */
47
	public function unregister(IPlayer $player, ?callable $onSelect, ?callable $onError = null): void
48
	{
49
		$this->connector->executeChange(self::REGISTER, [$player->getName()], $onSelect, $onError);
50
	}
51
52
	/**
53
	 * プレイヤーの情報を取得します
54
	 *
55
	 * @param IPlayer $player
56
	 * @param callable $onSelect
57
	 * @param callable|null $onError
58
	 */
59
	public function get(IPlayer $player, callable $onSelect, ?callable $onError = null): void
60
	{
61
		$this->connector->executeSelect(self::GET, [$player->getName()], $onSelect, $onError);
62
	}
63
64
	/**
65
	 * プレイヤーのそれぞれのカウントを増やします
66
	 *
67
	 * @param IPlayer $player
68
	 * @param int $kill
69
	 * @param int $death
70
	 * @param int $win
71
	 * @param int $lose
72
	 * @param callable|null $onSelect
73
	 * @param callable|null $onError
74
	 */
75
	public function add(IPlayer $player, int $kill = 0, int $death = 0, int $win = 0, int $lose = 0, ?callable $onSelect = null, ?callable $onError = null): void
76
	{
77
		$this->connector->executeChange(self::ADD_COUNT, [$player->getName(), $kill, $death, $win, $lose], $onSelect, $onError);
78
	}
79
80
	/**
81
	 * プレイヤーのキル数を増やします
82
	 *
83
	 * @param IPlayer $player
84
	 * @param int $kill
85
	 */
86
	public function addKill(IPlayer $player, int $kill): void
87
	{
88
		$this->add($player, $kill);
89
	}
90
91
	/**
92
	 * プレイヤーのデス数を増やします
93
	 *
94
	 * @param IPlayer $player
95
	 * @param int $death
96
	 */
97
	public function addDeath(IPlayer $player, int $death): void
98
	{
99
		$this->add($player, 0, $death);
100
	}
101
102
	/**
103
	 * プレイヤーの勝利数を増やします
104
	 *
105
	 * @param IPlayer $player
106
	 * @param int $win
107
	 */
108
	public function addWin(IPlayer $player, int $win): void
109
	{
110
		$this->add($player, 0, 0, $win);
111
	}
112
113
	/**
114
	 * プレイヤーの敗北数を増やします
115
	 *
116
	 * @param IPlayer $player
117
	 * @param int $lose
118
	 */
119
	public function addLose(IPlayer $player, int $lose): void
120
	{
121
		$this->add($player, 0, 0, 0, $lose);
122
	}
123
124
	/**
125
	 * 勝利数のランキングを取得します
126
	 *
127
	 * @param int $limit
128
	 * @param callable $onSelect
129
	 * @param callable|null $onError
130
	 */
131
	public function getRankingByWin(int $limit, callable $onSelect, ?callable $onError = null): void
132
	{
133
		$this->connector->executeSelect(self::GET_RANKING, [$limit], $onSelect, $onError);
134
	}
135
}