minor adjustments

This commit is contained in:
Steffen Schröder 2014-09-07 23:17:02 +02:00
parent d66a4e951e
commit 2de3423e0a

View File

@ -30,10 +30,11 @@ class BillManager implements CallbackListener {
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
/** @var BillData[] $openBills */
private $openBills = array(); private $openBills = array();
/** /**
* Construct a new Bill Manager Instance * Construct a new Bill Manager instance
* *
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
*/ */
@ -45,7 +46,7 @@ class BillManager implements CallbackListener {
} }
/** /**
* Send a Bill to a Player * Send a bill to a player
* *
* @param callable $function * @param callable $function
* @param Player $player * @param Player $player
@ -55,13 +56,13 @@ class BillManager implements CallbackListener {
* @return bool * @return bool
*/ */
public function sendBill(callable $function, Player $player, $amount, $message, $receiver = '') { public function sendBill(callable $function, Player $player, $amount, $message, $receiver = '') {
$bill = $this->maniaControl->getClient()->sendBill($player->login, $amount, $message, $receiver); $billId = $this->maniaControl->getClient()->sendBill($player->login, $amount, $message, $receiver);
$this->openBills[$bill] = new BillData($function, $player, $amount); $this->openBills[$billId] = new BillData($function, $player, $amount);
return true; return true;
} }
/** /**
* Send Planets from the server to a Player * Send planets from the server to a player
* *
* @param callable $function * @param callable $function
* @param string $receiverLogin * @param string $receiverLogin
@ -70,8 +71,8 @@ class BillManager implements CallbackListener {
* @return bool * @return bool
*/ */
public function sendPlanets(callable $function, $receiverLogin, $amount, $message) { public function sendPlanets(callable $function, $receiverLogin, $amount, $message) {
$bill = $this->maniaControl->getClient()->pay($receiverLogin, $amount, $message); $billId = $this->maniaControl->getClient()->pay($receiverLogin, $amount, $message);
$this->openBills[$bill] = new BillData($function, $receiverLogin, $amount, true); $this->openBills[$billId] = new BillData($function, $receiverLogin, $amount, true);
return true; return true;
} }
@ -83,12 +84,11 @@ class BillManager implements CallbackListener {
*/ */
public function handleBillUpdated(array $callback) { public function handleBillUpdated(array $callback) {
$billId = $callback[1][0]; $billId = $callback[1][0];
if (!array_key_exists($billId, $this->openBills)) { if (!isset($this->openBills[$billId])) {
return; return;
} }
$billData = $this->openBills[$billId]; $billData = $this->openBills[$billId];
/** @var BillData $billData */
switch ($callback[1][1]) { switch ($callback[1][1]) {
case Bill::STATE_PAYED: case Bill::STATE_PAYED:
if ($billData->pay) { if ($billData->pay) {