Completed
Pull Request — master (#307)
by
unknown
04:00
created

Donate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 74
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A configure() 0 9 1
A execute() 0 13 1
1
<?php
2
3
namespace eXpansion\Framework\GameCurrencyBundle\ChatCommand;
4
5
use eXpansion\Framework\Core\Helpers\ChatNotification;
6
use eXpansion\Framework\Core\Model\ChatCommand\AbstractChatCommand;
7
use eXpansion\Framework\Core\Storage\GameDataStorage;
8
use eXpansion\Framework\Core\Storage\PlayerStorage;
9
use eXpansion\Framework\GameCurrencyBundle\Plugins\Gui\BillWindow;
10
use eXpansion\Framework\GameCurrencyBundle\Services\GameCurrencyService;
11
use Symfony\Component\Console\Input\InputArgument;
12
use Symfony\Component\Console\Input\InputInterface;
13
14
/**
15
 *
16
 * @author  reaby
17
 */
18
class Donate extends AbstractChatCommand
19
{
20
    /** @var BillWindow */
21
    private $billWindow;
0 ignored issues
show
Unused Code introduced by
The property $billWindow is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22
    /**
23
     * @var GameCurrencyService
24
     */
25
    private $currencyService;
26
    /**
27
     * @var GameDataStorage
28
     */
29
    private $gameDataStorage;
30
    /**
31
     * @var ChatNotification
32
     */
33
    private $chatNotification;
34
    /**
35
     * @var PlayerStorage
36
     */
37
    private $playerStorage;
38
39
    /**
40
     * ScriptPanel constructor.
41
     *
42
     * @param                      $command
43
     * @param array                $aliases
44
     * @param GameCurrencyService  $currencyService
45
     * @param GameDataStorage      $gameDataStorage
46
     * @param ChatNotification     $chatNotification
47
     * @param PlayerStorage        $playerStorage
48
     */
49
    public function __construct(
50
        $command,
51
        array $aliases = [],
52
        GameCurrencyService $currencyService,
53
        GameDataStorage $gameDataStorage,
54
        ChatNotification $chatNotification,
55
        PlayerStorage $playerStorage
56
    ) {
57
        parent::__construct($command, $aliases);
58
        $this->currencyService = $currencyService;
59
        $this->gameDataStorage = $gameDataStorage;
60
        $this->chatNotification = $chatNotification;
61
        $this->playerStorage = $playerStorage;
62
    }
63
64
    protected function configure()
65
    {
66
        parent::configure();
67
68
        $this->inputDefinition->addArgument(
69
            new InputArgument('amount', InputArgument::REQUIRED, "amount to donate")
70
        );
71
72
    }
73
74
75
    /**
76
     * @inheritdoc
77
     */
78
    public function execute($login, InputInterface $input)
79
    {
80
        $amount = $input->getArgument("amount");
81
        $bill = $this->currencyService->createBill($login, $amount,
82
            $this->gameDataStorage->getSystemInfo()->serverLogin, "");
83
        $this->currencyService->sendBill($bill, function () use ($bill, $login) {
0 ignored issues
show
Security Bug introduced by
It seems like $bill defined by $this->currencyService->...nfo()->serverLogin, '') on line 81 can also be of type false; however, eXpansion\Framework\Game...encyService::sendBill() does only seem to accept object<eXpansion\Framewo...dle\Model\Gamecurrency>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
84
            $player = $this->playerStorage->getPlayerInfo($login);
85
            $amount = $bill->getAmount();
86
            $this->chatNotification->sendMessage('|info|{info}Server received {variable}'.$amount.'p {info}donation from {variable}'.$player->getNickName());
87
        }, function ($error) use ($login) {
88
            $this->chatNotification->sendMessage("|error|{info}Error while processing your donation: {error}".$error, $login);
89
        });
90
    }
91
}
92