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/CashGame.php (4 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\Deck;
6
use Cysha\Casino\Exceptions\GameException;
7
use Cysha\Casino\Game\Chips;
8
use Cysha\Casino\Game\Client;
9
use Cysha\Casino\Game\Contracts\Game;
10
use Cysha\Casino\Game\Contracts\GameParameters;
11
use Cysha\Casino\Game\PlayerCollection;
12
use Cysha\Casino\Game\TableCollection;
13
use Cysha\Casino\Holdem\Cards\Evaluators\SevenCard;
14
use Ramsey\Uuid\Uuid;
15
use Ramsey\Uuid\UuidInterface;
16
17
final class CashGame implements Game
18
{
19
    /**
20
     * @var UuidInterface
21
     */
22
    private $id;
23
24
    /**
25
     * @var string
26
     */
27
    private $name;
28
29
    /**
30
     * @var DefaultParameters
31
     */
32
    private $rules;
33
34
    /**
35
     * @var PlayerCollection
36
     */
37
    private $players;
38
39
    /**
40
     * @var TableCollection
41
     */
42
    protected $tables;
43
44
    /**
45
     * CashGame constructor.
46
     *
47
     * @param UuidInterface  $id
48
     * @param string         $name
49 66
     * @param GameParameters $rules
50
     */
51 66
    public function __construct(UuidInterface $id, string $name, GameParameters $rules)
52 66
    {
53 66
        $this->id = $id;
54 66
        $this->name = $name;
55 66
        $this->players = PlayerCollection::make();
56 66
        $this->tables = TableCollection::make();
57
        $this->rules = $rules;
0 ignored issues
show
Documentation Bug introduced by
It seems like $rules of type object<Cysha\Casino\Game...ntracts\GameParameters> is incompatible with the declared type object<Cysha\Casino\Hold...Game\DefaultParameters> of property $rules.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
    }
59
60
    /**
61
     * @param UuidInterface  $id
62
     * @param string         $name
63
     * @param GameParameters $rules
64
     *
65 66
     * @return CashGame
66
     */
67 66
    public static function setUp(UuidInterface $id, string $name, GameParameters $rules)
68
    {
69
        return new self($id, $name, $rules);
70
    }
71
72
    /**
73 1
     * @return UuidInterface
74
     */
75 1
    public function id(): UuidInterface
76
    {
77
        return $this->id;
78
    }
79
80
    /**
81 1
     * @return string
82
     */
83 1
    public function name(): string
84
    {
85
        return $this->name;
86
    }
87
88
    /**
89 4
     * @return GameParameters
90
     */
91 4
    public function rules(): GameParameters
92
    {
93
        return $this->rules;
94
    }
95
96
    /**
97 63
     * @return PlayerCollection
98
     */
99 63
    public function players(): PlayerCollection
100
    {
101
        return $this->players;
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function __toString(): string
108 62
    {
109
        return $this->name;
110 62
    }
111
112 62
    /**
113
     * @return TableCollection
114 59
     */
115 62
    public function tables(): TableCollection
116
    {
117 62
        return $this->tables;
118 1
    }
119
120
    /**
121 62
     * @param Client $client
122 1
     * @param Chips  $buyinAmount
123
     *
124
     * @throws GameException
125 61
     */
126
    public function registerPlayer(Client $client, Chips $buyinAmount = null)
127 61
    {
128 61
        $buyinAmount = $buyinAmount ?? $this->rules()->minimumBuyIn();
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Cysha\Casino\Game\Contracts\GameParameters as the method minimumBuyIn() does only exist in the following implementations of said interface: Cysha\Casino\Holdem\Game...ters\CashGameParameters.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
129 61
130
        $playerRegistered = $this->players()
131
            ->filter(function (Client $player) use ($client) {
132
                return $client->name() === $player->name();
133
            });
134 2
135
        if ($playerRegistered->count() !== 0) {
136 2
            throw GameException::alreadyRegistered($client, $this);
137
        }
138
139
        if ($buyinAmount->amount() > $client->wallet()->amount()) {
140
            throw GameException::insufficientFunds($client, $this);
141
        }
142 57
143
        $client->wallet()->subtract($buyinAmount);
144
145 57
        $addPlayer = Player::fromClient($client, $buyinAmount);
146
        $this->players()->push($addPlayer);
147 57
    }
148 57
149
    public function removePlayer(Client $client)
150 57
    {
151 57
        $player = $this->players()
152 57
            ->filter(function (Player $player) use ($client) {
153
                return $player->name() === $client->name();
154
            })
155
            ->first()
156
        ;
157 54
158
        if ($player === null) {
159 54
            throw GameException::notRegistered($client, $this);
160
        }
161
162
        $client->wallet()->add($player->chipstack());
163
164
        $this->players = $this->players()
165
            ->reject(function (Player $player) use ($client) {
166
                return $player->name() === $client->name();
167
            })
168
            ->values();
169
170
        $this->tables()
171
            ->each(function (Table $table) use ($client) {
172
                try {
173
                    $table->removePlayer($client);
174
                } catch (Cysha\Casino\Holdem\Exceptions\TableException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
The class Cysha\Casino\Holdem\Game...ceptions\TableException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
175
                }
176
            });
177
    }
178
179
    public function assignPlayersToTables()
180
    {
181
        $groupedPlayers = $this->players()
182
        //->shuffle()
183
            ->chunk($this->rules()->tableSize())
184
            ->map(function (PlayerCollection $players) {
185
                $dealer = Dealer::startWork(new Deck(), new SevenCard());
186
187
                return Table::setUp(Uuid::uuid4(), $dealer, $players);
188
            })
189
            ->toArray();
190
191
        $this->tables = TableCollection::make($groupedPlayers);
192
    }
193
}
194