Issues (1)

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/Handler/GameResultHandler.php (1 issue)

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 MiniGameMessageApp\Handler;
4
5
use League\Event\EventInterface;
6
use MessageApp\Finder\MessageFinder;
7
use MessageApp\Listener\MessageEventHandler;
8
use MessageApp\Message\MessageFactory;
9
use MessageApp\Message\Sender\MessageSender;
10
use MessageApp\User\ApplicationUser;
11
use MessageApp\User\Finder\ContextUserFinder;
12
use MiniGame\Entity\PlayerId;
13
use MiniGame\GameResult;
14
use MiniGame\Result\AllPlayersResult;
15
use MiniGameMessageApp\Finder\MiniGameUserFinder;
16
use Psr\Log\LoggerAwareInterface;
17
use Psr\Log\LoggerAwareTrait;
18
use Psr\Log\NullLogger;
19
use RemiSan\Context\Context;
20
21
class GameResultHandler implements MessageEventHandler, LoggerAwareInterface
22
{
23
    use LoggerAwareTrait;
24
25
    /**
26
     * @var MiniGameUserFinder
27
     */
28
    private $userFinder;
29
30
    /**
31
     * @var ContextUserFinder
32
     */
33
    private $contextUserFinder;
34
35
    /**
36
     * @var MessageFinder
37
     */
38
    private $messageFinder;
39
40
    /**
41
     * @var MessageFactory
42
     */
43
    private $messageFactory;
44
45
    /**
46
     * @var MessageSender
47
     */
48
    private $messageSender;
49
50
    /**
51
     * Constructor
52
     *
53
     * @param MiniGameUserFinder $userFinder
54
     * @param ContextUserFinder  $contextUserFinder
55
     * @param MessageFinder      $messageFinder
56
     * @param MessageFactory     $messageFactory
57
     * @param MessageSender      $messageSender
58
     */
59 18
    public function __construct(
60
        MiniGameUserFinder $userFinder,
61
        ContextUserFinder $contextUserFinder,
62
        MessageFinder $messageFinder,
63
        MessageFactory $messageFactory,
64
        MessageSender $messageSender
65
    ) {
66 18
        $this->userFinder = $userFinder;
67 18
        $this->contextUserFinder = $contextUserFinder;
68 18
        $this->messageFinder = $messageFinder;
69 18
        $this->messageFactory = $messageFactory;
70 18
        $this->messageSender = $messageSender;
71 18
        $this->logger = new NullLogger();
72 18
    }
73
74
    /**
75
     * Handle an event.
76
     *
77
     * @param EventInterface $event
78
     * @param Context        $context
79
     *
80
     * @return void
81
     */
82 18
    public function handle(EventInterface $event, Context $context = null)
83
    {
84 18
        if (! $event instanceof GameResult) {
85 3
            return;
86
        }
87
88 15
        $this->logger->info(sprintf('Send message after "%s"', $event->getName()));
89 15
        $messageContext = $this->getMessageContext($context);
90
91 15
        $users = $this->getUsersList($event, $messageContext);
92
93 12
        $this->sendMessage($event, $users, $messageContext);
0 ignored issues
show
$users is of type array<integer,object<Mes...\ApplicationUser>|null>, but the function expects a array<integer,object<Mes...\User\ApplicationUser>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
94 12
    }
95
96
    /**
97
     * @param  GameResult        $gameResult
98
     * @param  ApplicationUser[] $users
99
     * @param  mixed             $messageContext
100
     * @return void
101
     */
102 12
    private function sendMessage(GameResult $gameResult, array $users = [], $messageContext = null)
103
    {
104 12
        $message = $this->messageFactory->buildMessage($users, $gameResult);
105
106 12
        if (!$message) {
107 3
            $this->logger->warning('Message could not be generated');
108 3
            return;
109
        }
110
111 9
        $this->messageSender->send($message, $messageContext);
112 9
    }
113
114
    /**
115
     * @param  Context $context
116
     * @return mixed
117
     */
118 15
    private function getMessageContext(Context $context = null)
119
    {
120 15
        if (!$context) {
121 9
            return null;
122
        }
123
124 6
        $message = $this->messageFinder->findByReference($context->getValue());
125 6
        return ($message) ? $message->getSource() : null;
126
    }
127
128
    /**
129
     * @param  PlayerId $playerId
130
     * @param  mixed    $contextMessage
131
     * @return ApplicationUser
132
     */
133 12
    private function getUser(PlayerId $playerId = null, $contextMessage = null)
134
    {
135
        // Build message
136 12
        $user = $this->getUserByPlayerId($playerId);
137 12
        if (!$user) {
138 9
            $this->logger->debug('Try to get user by context message');
139 9
            $user = $this->getUserByContext($contextMessage);
140 9
            if (!$user) {
141 6
                if (!$playerId) {
142 3
                    $this->logger->debug('No user was found');
143 3
                    return null;
144
                }
145 3
                throw new \InvalidArgumentException('User not found!');
146
            }
147 2
        }
148
149 6
        return $user;
150
    }
151
152
    /**
153
     * @param  PlayerId $id
154
     * @return ApplicationUser
155
     */
156 12
    private function getUserByPlayerId(PlayerId $id = null)
157
    {
158 12
        return ($id) ? $this->userFinder->getByPlayerId($id) : null;
159
    }
160
161
    /**
162
     * @param  mixed $contextMessage
163
     * @return ApplicationUser
164
     */
165 9
    private function getUserByContext($contextMessage = null)
166
    {
167 9
        if (!$contextMessage) {
168 3
            $this->logger->debug('No context message to retrieve user from');
169 3
            return null;
170
        };
171
172 6
        return $this->contextUserFinder->getUserByContextMessage($contextMessage);
173
    }
174
175
    /**
176
     * @param GameResult $event
177
     * @param mixed      $messageContext
178
     *
179
     * @return ApplicationUser[]
180
     */
181 15
    private function getUsersList(GameResult $event, $messageContext)
182
    {
183 15
        if ($event instanceof AllPlayersResult) {
184 3
            return $this->userFinder->getByGameId($event->getGameId());
185
        }
186
187 12
        return [ $this->getUser($event->getPlayerId(), $messageContext) ];
188
    }
189
}
190