Issues (121)

Security Analysis    not enabled

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.

app/Http/Requests/MatchUpdate.php (5 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 App\Http\Requests;
4
5
use App\Events\MatchWasFinished;
6
use App\Listeners\Match\UpdateResultType;
7
use App\Match;
8
use App\Tournament;
9
use Illuminate\Support\Collection;
10
use Illuminate\Support\Facades\Auth;
11
use Illuminate\Support\Facades\Validator;
12
13
/**
14
 * Class MatchUpdate
15
 * @package App\Http\Requests
16
 */
17
class MatchUpdate extends Request
18
{
19
    /**
20
     * Determine if the user is authorized to make this request.
21
     *
22
     * @return bool
23
     */
24
    public function authorize()
25
    {
26
        return Auth::check();
27
    }
28
29
    /**
30
     * Get the validation rules that apply to the request.
31
     *
32
     * @return array
33
     */
34
    public function rules()
35
    {
36
        $matchId = $this->route('matchId');
37
38
        /**
39
         * Copy of match row
40
         *
41
         * @var $match Match
42
         */
43
        $match = Match::findOrFail($matchId)->replicate();
44
        $tournament = $match->tournament()->get()->first();
45
46
        Validator::extend('round_active', function ($attribute, $value, $parameters) use ($match, $tournament) {
0 ignored issues
show
The parameter $attribute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
            return $this->isRoundActive($match, $tournament);
48
        });
49
50
        Validator::extend(
51
            'round_finished_for_pair',
52
            function ($attribute, $value, $parameters) use ($match, $tournament) {
0 ignored issues
show
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
                $match->status = $value;
0 ignored issues
show
The property status does not exist on object<App\Match>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
54
                return $this->isRoundFinishedForPair($match, $tournament);
55
            }
56
        );
57
58
        $statuses = implode(',', Match::getAvailableStatuses());
59
60
        return [
61
            'match.homeScore' => 'required|integer',
62
            'match.awayScore' => 'required|integer',
63
            'match.status' => 'required|in:' . $statuses . '|round_active|round_finished_for_pair'
64
        ];
65
    }
66
67
    /**
68
     * @param $match
69
     * @param $tournament
70
     * @return bool
71
     */
72
    protected function isRoundActive($match, $tournament)
73
    {
74
75
        // rule is not applied for Leagues
76
        if (Tournament::TYPE_LEAGUE === $tournament->type) {
77
            return true;
78
        }
79
80
        // rule is not applied for group stage matches
81
        if (Match::GAME_TYPE_GROUP_STAGE === $match->gameType) {
82
            return true;
83
        }
84
85
        return $match->round === $tournament->getCurrentRound();
86
    }
87
88
    /**
89
     * @param $match
90
     * @param $tournament Tournament
91
     * @return bool
92
     */
93
    protected function isRoundFinishedForPair($match, $tournament)
94
    {
95
        // rule is not applied for Leagues
96
        if (Tournament::TYPE_LEAGUE === $tournament->type) {
97
            return true;
98
        }
99
100
        // rule is not applied for group stage matches
101
        if (Match::GAME_TYPE_GROUP_STAGE === $match->gameType) {
102
            return true;
103
        }
104
105
        $match->fill(array_get($this->only(['match.homeScore', 'match.awayScore', 'match.status']), 'match'));
106
107
        $event = new MatchWasFinished($match);
108
109
        $listener = new UpdateResultType();
110
        $listener->handle($event);
111
112
        $secondMatchForPair = Match::where([
113
            'round' => $match->round,
114
            'homeTournamentTeamId' => $match->awayTournamentTeamId,
115
            'awayTournamentTeamId' => $match->homeTournamentTeamId
116
        ])->first();
117
118
        $matches = new Collection([$event->match, $secondMatchForPair]);
119
120
        // all matches in pair should have `finished` status
121
        if ($matches->where('status', Match::STATUS_FINISHED)->count() < 2) {
122
            return true;
123
        }
124
125
        $score = $tournament->getScore($matches);
126
127
        return 2 === $score->unique('position')->count();
128
    }
129
}
130