-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.php
More file actions
95 lines (82 loc) · 2.46 KB
/
Player.php
File metadata and controls
95 lines (82 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
require_once 'arrayExtract.php';
class Player
{
private $final_rank;
private $match_history;
private $id;
private $name;
private $seed;
private $tournament_id;
/**
* Creates a new player Object
* Does not include id, seed, or tournament_id
* @param array $playerArray An associative array from the playerRip
*/
function __construct($playerArray){
$this->name = arrayExtract($playerArray, "name", "string");
$this->final_rank = arrayExtract($playerArray, "rank", "int");
$this->match_history = arrayExtract($playerArray, "match_history", "array");
}
/**
* Sets the id
* @param int $id
*/
function setId(int $id){
$this->id = $id;
}
/**
* Sets the seed
* @param int $seed
*/
function setSeed(int $seed){
$this->seed = $seed;
}
/**
* Sets the tournament_id
* @param int $tournament
*/
function setTournamentId(int $tournament){
$this->tournament_id = $tournament;
}
/**
* Returns the value of a specific index, much like JSON
* @param string $indexString The value which is indexed
* @throws OutOfBoundsException if index is invalid
*/
public function index($indexString) {
switch ($indexString) {
case "final_rank":
return $this->final_rank;
break;
case "id":
return $this->id;
break;
case "name":
return $this->name;
break;
case "seed":
return $this->seed;
break;
case "tournament_id":
return $this->tournament_id;
break;
case "match_history":
return $this->match_history;
break;
default:
throw new OutOfBoundsException($indexString." is not a valid index of Player!");
break;
}
}
public function toArray(){
return array(
"final_rank" => $this->final_rank,
"match_history" => $this->match_history,
"id" => $this->id,
"name" => $this->name,
"seed" => $this->seed,
"tournament_id" => $this->tournament_id
);
}
}