Code smell.
This commit is contained in:
@@ -7,13 +7,13 @@ use Battles\Database\Db;
|
||||
class UserMoney
|
||||
{
|
||||
private int $uid;
|
||||
private int $wallet_money;
|
||||
private int $walletMoney;
|
||||
private Bank $bank;
|
||||
|
||||
public function __construct(int $uid, int $money)
|
||||
{
|
||||
$this->uid = $uid;
|
||||
$this->wallet_money = $money;
|
||||
$this->walletMoney = $money;
|
||||
$this->initBank();
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ class UserMoney
|
||||
|
||||
public function get(): int
|
||||
{
|
||||
return $this->wallet_money;
|
||||
return $this->walletMoney;
|
||||
}
|
||||
|
||||
public function set(int $money)
|
||||
{
|
||||
$this->wallet_money = max($money, 0);
|
||||
$this->walletMoney = max($money, 0);
|
||||
}
|
||||
|
||||
public function getBank(): int
|
||||
@@ -44,14 +44,14 @@ class UserMoney
|
||||
|
||||
private function save()
|
||||
{
|
||||
Db::getInstance()->execute('update users set money = ? where id = ?', [$this->wallet_money, $this->uid]);
|
||||
Db::getInstance()->execute('update users set money = ? where id = ?', [$this->walletMoney, $this->uid]);
|
||||
}
|
||||
|
||||
/** Тратим деньги */
|
||||
public function spend(int $value): bool
|
||||
{
|
||||
if ($this->wallet_money > $value && $value > 0) {
|
||||
$this->wallet_money -= $value;
|
||||
if ($this->walletMoney > $value && $value > 0) {
|
||||
$this->walletMoney -= $value;
|
||||
$this->save();
|
||||
return true;
|
||||
}
|
||||
@@ -64,8 +64,8 @@ class UserMoney
|
||||
if ($value <= 0) {
|
||||
return false;
|
||||
}
|
||||
$this->wallet_money += $value;
|
||||
$this->walletMoney += $value;
|
||||
$this->save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user