Issues (72)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Game/Dealer.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Cysha\Casino\Holdem\Game;
4
5
use Cysha\Casino\Cards\Card;
6
use Cysha\Casino\Cards\CardCollection;
7
use Cysha\Casino\Cards\Contracts\CardEvaluator;
8
use Cysha\Casino\Cards\Deck;
9
use Cysha\Casino\Cards\Hand;
10
use Cysha\Casino\Cards\HandCollection;
11
use Cysha\Casino\Cards\ResultCollection;
12
use Cysha\Casino\Game\Contracts\Dealer as DealerContract;
13
use Cysha\Casino\Game\Contracts\Player as PlayerContract;
14
use Cysha\Casino\Game\Dealer as BaseDealer;
15
use Cysha\Casino\Game\PlayerCollection;
16
use Cysha\Casino\Holdem\Exceptions\RoundException;
17
18
class Dealer extends BaseDealer implements DealerContract
19
{
20
    /**
21
     * @var Deck
22
     */
23
    private $deck;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
24
25
    /**
26
     * @var CardEvaluator
27
     */
28
    private $cardEvaluationRules;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
29
30
    /**
31 78
     * @var CardCollection
32
     */
33 78
    private $communityCards;
34 78
35 78
    /**
36
     * @var CardCollection
37
     */
38
    private $burnCards;
39
40
    /**
41
     * @var HandCollection
42
     */
43 78
    private $hands;
44
45 78
    /**
46
     * Dealer constructor.
47
     *
48
     * @param Deck          $deck
49
     * @param CardEvaluator $cardEvaluationRules
50
     */
51 50
    private function __construct(Deck $deck, CardEvaluator $cardEvaluationRules)
0 ignored issues
show
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
52
    {
53 50
        $this->deck = $deck;
54
        $this->cardEvaluationRules = $cardEvaluationRules;
55
56
        $this->communityCards = CardCollection::make();
57
        $this->burnCards = CardCollection::make();
58
        $this->hands = HandCollection::make();
59 23
    }
60
61 23
    /**
62
     * @param Deck          $deck
63
     * @param CardEvaluator $cardEvaluationRules
64
     *
65
     * @return Dealer
66
     */
67 50
    public static function startWork(Deck $deck, CardEvaluator $cardEvaluationRules)
68
    {
69 50
        return new self($deck, $cardEvaluationRules);
70 50
    }
71
72
    /**
73
     * @return Deck
74
     */
75
    public function deck(): Deck
76
    {
77
        return $this->deck;
78 22
    }
79
80 22
    /**
81
     * @return CardCollection
82
     */
83
    public function communityCards(): CardCollection
84
    {
85
        return $this->communityCards;
86
    }
87
88
    /**
89
     * @return CardCollection
90
     */
91
    public function burnCards(): CardCollection
92
    {
93
        return $this->burnCards;
94
    }
95
96
    /**
97
     * @return Card
98
     */
99
    public function dealCard(): Card
100
    {
101
        return $this->deck()->draw();
102
    }
103
104
    /**
105
     * @return HandCollection
106
     */
107
    public function hands(): HandCollection
108
    {
109
        return $this->hands;
110
    }
111
112
    /**
113
     * Shuffles the deck.
114
     */
115
    public function shuffleDeck()
116
    {
117
        $this->deck()->shuffle();
118
    }
119
120
    /**
121
     * Adds a card to the BurnCards(), also Adds a card to the CommunityCards().
122
     *
123
     * @param int $cards
124
     */
125
    public function dealCommunityCards(int $cards = 1)
126
    {
127
        // burn one
128
        $this->burnCards()->push($this->dealCard());
129
130
        // deal
131
        for ($i = 0; $i < $cards; ++$i) {
132
            $this->communityCards()->push($this->dealCard());
133
        }
134
    }
135
136
    /**
137
     * Deals the remainder of the community cards, whilst taking burn cards into account.
138
     */
139
    public function checkCommunityCards()
140
    {
141
        if ($this->communityCards()->count() === 5) {
142
            return;
143
        }
144
145
        if ($this->communityCards()->count() === 0) {
146
            $this->dealCommunityCards(3);
147
        }
148
149
        if ($this->communityCards()->count() === 3) {
150
            $this->dealCommunityCards(1);
151
        }
152
153
        if ($this->communityCards()->count() === 4) {
154
            $this->dealCommunityCards(1);
155
        }
156
    }
157
158
    /**
159
     * Deal the hands to the players.
160
     */
161
    public function dealHands(PlayerCollection $players)
162
    {
163
        $this->hands = $this->dealCardsToPlayers($players);
164
    }
165
166
    /**
167
     * @param PlayerContract $player
168
     *
169
     * @return Hand
170
     */
171
    public function playerHand(PlayerContract $player): Hand
172
    {
173
        $hand = $this->hands()->findByPlayer($player);
174
175
        if ($hand === null) {
176
            throw RoundException::playerHasNoHand($player);
177
        }
178
179
        return $hand;
180
    }
181
182
    /**
183
     * @return HandCollection
184
     */
185
    public function dealCardsToPlayers(PlayerCollection $players): HandCollection
186
    {
187
        $hands = HandCollection::make();
188
189
        // deal to the player after the button first
190
        $players
191
            ->each(function (PlayerContract $player) use ($hands) {
192
                $hands->push(Hand::create(CardCollection::make([
193
                    $this->dealCard(),
194
                ]), $player));
195
            })
196
            ->each(function (PlayerContract $player) use ($hands) {
197
                $hands->map(function (Hand $hand) use ($player, $hands) {
198
                    if ($hand->player()->equals($player) === false) {
199
                        return false;
200
                    }
201
202
                    return $hand->addCard($this->dealCard());
203
                });
204
            });
205
206
        return $hands;
207
    }
208
209
    /**
210
     * @param CardCollection $board
211
     * @param HandCollection $playerHands
212
     *
213
     * @return ResultCollection
214
     */
215
    public function evaluateHands(CardCollection $board, HandCollection $playerHands): ResultCollection
216
    {
217
        return $this->cardEvaluationRules->evaluateHands($board, $playerHands);
218
    }
219
}
220