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/Action.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\CardCollection;
6
use Cysha\Casino\Game\Chips;
7
use Cysha\Casino\Game\Contracts\Name as NameContract;
8
use InvalidArgumentException;
9
10
class Action
11
{
12
    const DEALT_RIVER = 9;
13
    const DEALT_TURN = 8;
14
    const DEALT_FLOP = 7;
15
16
    const BIG_BLIND = 6;
17
    const SMALL_BLIND = 5;
18
19
    const ALLIN = 4;
20
    const FOLD = 3;
21
    const RAISE = 2;
22
    const CALL = 1;
23
    const CHECK = 0;
24
25
    /**
26
     * @var
27
     */
28
    private $player;
29
30
    /**
31
     * @var int
32 45
     */
33
    private $action;
34 45
35 45
    /**
36 45
     * @var Chips
37 45
     */
38
    private $chips;
39
40
    public function __construct(NameContract $player, int $action, $attributes = [])
41
    {
42 1
        if (isset($attributes['chips']) && !($attributes['chips'] instanceof Chips)) {
43
            throw new InvalidArgumentException('Chip attribute should be instance of Chips');
44 1
        }
45
46
        if (isset($attributes['communityCards']) && !($attributes['communityCards'] instanceof CardCollection)) {
47
            throw new InvalidArgumentException('communityCards attribute should be instance of CardCollection');
48
        }
49
50 1
        $this->player = $player;
51
        $this->action = $action;
52 1
        $this->communityCards = $attributes['communityCards'] ?? CardCollection::make();
0 ignored issues
show
The property communityCards does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
53
        $this->chips = $attributes['chips'] ?? Chips::zero();
0 ignored issues
show
Documentation Bug introduced by
It seems like $attributes['chips'] ?? ...sino\Game\Chips::zero() can also be of type object<self>. However, the property $chips is declared as type object<Cysha\Casino\Game\Chips>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
54
    }
55
56
    /**
57
     * @return int
58 1
     */
59
    public function action(): int
60 1
    {
61
        return $this->action;
62
    }
63 7
64
    /**
65 7
     * @return
66 7
     */
67 7
    public function player()
68 1
    {
69 1
        return $this->player;
70
    }
71 6
72 1
    /**
73 1
     * @return Chips
74
     */
75 5
    public function chips(): Chips
76 1
    {
77 1
        return $this->chips;
78
    }
79 4
80 1
    /**
81 1
     * @return CardCollection
82
     */
83 3
    public function communityCards(): CardCollection
84 1
    {
85 1
        return $this->communityCards;
86
    }
87 2
88 1
    public function toString()
89 1
    {
90
        $message = null;
91 1
        switch ($this->action) {
92 1
            case static::DEALT_RIVER:
0 ignored issues
show
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
93 1
                $message = sprintf('%s has dealt the river (%s).', $this->player->name(), $this->communityCards()->__toString());
94
                break;
95
96 7
            case static::DEALT_TURN:
97
                $message = sprintf('%s has dealt the turn (%s).', $this->player->name(), $this->communityCards()->__toString());
98
                break;
99 7
100
            case static::DEALT_FLOP:
101 7
                $message = sprintf('%s has dealt the flop (%s).', $this->player->name(), $this->communityCards()->__toString());
102
                break;
103
104
            case static::BIG_BLIND:
105
                $message = sprintf('%s has posted Big Blind (%d).', $this->player->name(), $this->chips->amount());
106
                break;
107
108
            case static::SMALL_BLIND:
109
                $message = sprintf('%s has posted Small Blind (%d).', $this->player->name(), $this->chips->amount());
110
                break;
111
112
            case static::ALLIN:
113
                $message = sprintf('%s has pushed ALL IN (%d).', $this->player->name(), $this->chips->amount());
114
                break;
115
116
            case static::FOLD:
117
                $message = sprintf('%s has folded.', $this->player->name());
118
                break;
119
120
            case static::RAISE:
121
                $message = sprintf('%s has raised %d.', $this->player->name(), $this->chips->amount());
122
                break;
123
124
            case static::CALL:
125
                $message = sprintf('%s has called %d.', $this->player->name(), $this->chips->amount());
126
                break;
127
128
            case static::CHECK:
129
                $message = sprintf('%s has checked.', $this->player->name());
130
                break;
131
        }
132
133
        return $message;
134
    }
135
136
    public function __toString()
137
    {
138
        return $this->toString();
139
    }
140
}
141