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/LeftToAct.php (2 issues)

Labels
Severity

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\Game\Contracts\Player;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Cysha\Casino\Holdem\Game\Player.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Cysha\Casino\Game\PlayerCollection;
7
use Illuminate\Support\Collection;
8
9
class LeftToAct extends Collection
10
{
11
    const BIG_BLIND = 6;
12
    const SMALL_BLIND = 5;
13
    const ALLIN = 3;
14
    const AGGRESSIVELY_ACTIONED = 2;
15
    const STILL_TO_ACT = 1;
16
    const ACTIONED = 0;
17
18
    /**
19
     * Sets all players actions to STILL_TO_ACT.
20
     *
21
     * @param PlayerCollection $players
22
     *
23
     * @return LeftToAct
24
     */
25 58
    public function setup(PlayerCollection $players): self
26
    {
27
        $collection = $players->map(function (Player $player, $seatNumber) {
28
            // everyone is still left to act
29
            return [
30 58
                'seat' => $seatNumber,
31 58
                'player' => $player->name(),
32 58
                'action' => self::STILL_TO_ACT,
33
            ];
34 58
        });
35
36 58
        return self::make($collection->toArray());
37
    }
38
39
    /**
40
     * Resets all players, and move dealer to the bottom of queue.
41
     *
42
     * @param PlayerCollection $players
43
     *
44
     * @return LeftToAct
45
     */
46 1
    public function setupWithoutDealer(PlayerCollection $players): self
47
    {
48 1
        $collection = $this->setup($players);
49
50
        // move the dealer to last
51 1
        $collection = $collection->movePlayerToLastInQueue();
52
53 1
        return self::make($collection->values()->toArray());
54
    }
55
56
    /**
57
     * @return LeftToAct
58
     */
59 27
    public function resetActions(): self
60
    {
61
        $collection = $this
62
            ->transform(function ($array) {
63 27
                if ($array['action'] !== self::ALLIN) {
64 27
                    $array['action'] = self::STILL_TO_ACT;
65
                }
66
67 27
                return $array;
68 27
            })
69 27
            ->values();
70
71 27
        return self::make($collection->values()->toArray());
72
    }
73
74
    /**
75
     * @return LeftToAct
76
     */
77 16
    public function sortBySeats(): self
78
    {
79
        $collection = $this
80
            ->sortBy(function ($array) {
81 16
                return $array['seat'];
82 16
            }, SORT_NUMERIC)
83 16
            ->values();
84
85 16
        return self::make($collection->values()->toArray());
86
    }
87
88
    /**
89
     * @return LeftToAct
90
     */
91 39
    public function playerHasActioned(Player $player, int $value = 0): self
92
    {
93 39
        $collection = $this->movePlayerToLastInQueue();
94 39
        if (in_array($value, [self::AGGRESSIVELY_ACTIONED, self::ALLIN])) {
95 16
            $collection = $collection->resetActions();
96
        }
97
98 39
        $collection->setActivity($player->name(), $value);
99
100 39
        return self::make($collection->values()->toArray());
101
    }
102
103
    /**
104
     * @param Player $player
105
     * @param int    $activity
106
     *
107
     * @return LeftToAct
108
     */
109 40
    public function setActivity($player, int $activity): self
110
    {
111
        // var_dump($this);
112
        $result = $this
113
            ->filter(function ($array) use ($player) {
114 40
                return $array['player'] === $player;
115 40
            })
116
        ;
117
118 40
        $array = $result->first();
119 40
        $array['action'] = $activity;
120 40
        $this->put($result->keys()->first(), $array);
121
122 40
        return self::make($this->values()->toArray());
123
    }
124
125
    /**
126
     * @return LeftToAct
127
     */
128 41
    public function movePlayerToLastInQueue(): self
129
    {
130 41
        $collection = $this->splice(1)->merge($this->splice(0, 1));
131
132 41
        return self::make($collection->values()->toArray());
133
    }
134
135
    /**
136
     * @return LeftToAct
137
     */
138 50
    public function resetPlayerListFromSeat(int $seatNumber): self
139
    {
140 50
        $firstPlayer = $this->first();
141 50
        if ($seatNumber === $firstPlayer['seat']) {
142 5
            return self::make($this->values()->toArray());
143
        }
144
145
        $new = $this->sortBy(function ($value) use ($seatNumber) {
146 47
            if ($value['seat'] < $seatNumber) {
147 47
                return ($value['seat'] + 1) * 10;
148
            }
149
150 47
            return $value['seat'];
151 47
        });
152
153 47
        return new self($new->values());
154
    }
155
156
    /**
157
     * @return LeftToAct
158
     */
159 14
    public function removePlayer(Player $player): self
160
    {
161
        $collection = $this
162
            ->reject(function ($array) use ($player) {
163 14
                return $array['player'] === $player->name();
164 14
            });
165
166 14
        return self::make($collection->values()->toArray());
167
    }
168
169
    /**
170
     * @return self
171
     */
172
    public function findByAction(int $action)
173
    {
174
        return $this->filter(function ($value) use ($action) {
175 36
            return $value['action'] === $action;
176 36
        });
177 36
    }
178 36
179
    /**
180
     * @return array
181
     */
182
    public function getRemainingPlayers()
183
    {
184
        return $this
185
            ->reject(function ($value) {
186
                return in_array($value['action'], [self::ACTIONED, self::AGGRESSIVELY_ACTIONED, self::ALLIN]);
187
            });
188
    }
189
190
    /**
191
     * @return array
192
     */
193
    public function getNextPlayer()
194
    {
195
        return $this->getRemainingPlayers()->first();
0 ignored issues
show
The method first cannot be called on $this->getRemainingPlayers() (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
196
    }
197
}
198