Issues (103)

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/controllers/LeagueController.php (18 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
use Illuminate\Support\Collection;
4
class GraphMovie {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
	public $earnings;
6
	private $earliest = NULL;
7
	public function __construct() {
8
		$this->earnings = new Collection();
9
	}
10
	public function addEarning($date,$earning) {
11
		$this->earnings->put($date,$earning);
12
		if (($this->earliest != NULL && $date < $this->earliest) || $this->earliest == NULL) {
13
			$this->earliest = $date;
14
		}
15
	}
16
	public function sort() {
17
		$this->earnings->sortBy(function($role){return $role;});
18
	}
19
	public function getEarningForDate($date) {
20
		//No data yet
21
		if(count($this->earnings)==0) {
22
			return 0;
23
		}
24
		//Data exists
25
		if($this->earnings->contains($date)) {
26
			return $this->earnings->get($date);
27
		}
28
		
29
		//Before earliest data
30
		//if ($this->earliest != NULL && $date < $this->earliest) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
		//	return 0;
32
		//}
33
		
34
		//Gap somewhere. Iterate through earnings and find the 
35
		//Assume sorted
36
		$retval = 0;
37
		foreach ($this->earnings->keys() as $checkdate) {
38
			if ($checkdate > $date) {
39
				return $retval; //Return the entry before this 
40
			}
41
			$retval = $this->earnings->get($checkdate);
42
		}
43
		
44
		//?
45
		return $retval;
46
	}
47
}
48
class LeagueController extends PageController {
0 ignored issues
show
The property $league_valid_rules is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
49
50
51
	/**
52
	 * Leagues list page
53
	 */
54 1
	public function index() {
55 1
		$search = Input::all();
56
57
		// Generate seasons array, also default season.
58 1
		$seasons_list = [];
59 1
		$seasons = Config::get('draft.seasons');
60 1
		$now = Carbon::now();
61
62 1
		if (isset($search['season']) && ! array_key_exists($search['season'], $seasons) && $search['season'] != 0) {
63
			unset($search['season']);
64
		}
65
66 1
		foreach ($seasons as $key => $info) {
67 1
			$seasons_list[$key] = $info['name'];
68 1
			if (! isset($search['season'])) {
69 1
				$start = call_user_func_array(['Carbon', 'create'], $info['start']);
70 1
				$end = call_user_func_array(['Carbon', 'create'], $info['end']);
71 1
				if ($now->between($start, $end)) {
72 1
					$search['season'] = $key;
73 1
				}
74 1
			}
75 1
		}
76
		// Generate years array, also default year
77 1
		$years_list = range($now->year + 1, Config::get('draft.earliest_year'), -1);
78 1
		$years_list = array_combine($years_list, $years_list);
79 1
		if (! isset($search['year']) || ! isset($years_list[$search['year']])) {
80 1
			$search['year'] = $now->year;
81 1
		}
82 1
		if(! isset($search['inactive'])) {
83 1
			$search['inactive'] = false;
84 1
		}
85
86
		// Generate the query
87
		/** @type League|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $leagues_query */
88 1
		$leagues_query = League::query();
89
90 1
		$leagues_query->where('private', 0);
0 ignored issues
show
The method where does only exist in Illuminate\Database\Eloq...\Database\Query\Builder, but not in League.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
91
92
		// Season
93 1
		if ($search['season'] != 0) {
94 1
			$leagues_query->season($search['year'], $search['season']);
0 ignored issues
show
The method season does only exist in League, but not in Illuminate\Database\Eloq...\Database\Query\Builder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
95 1
		}
96
		// Active
97 1
		$leagues_query->where('active', !$search['inactive']);
0 ignored issues
show
!$search['inactive'] is of type boolean, but the function expects a string|null.

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...
98
99
100 1
		$leagues = $leagues_query->paginate(10);
0 ignored issues
show
The method paginate does only exist in Illuminate\Database\Eloq...\Database\Query\Builder, but not in League.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
101
102
		// Output
103 1
		$this->layout->title = 'Leagues';
104 1
		$this->layout->content = View::make('league.index', [
105 1
			'leagues' => $leagues,
106 1
			'seasons' => $seasons_list,
107 1
			'years'   => $years_list,
108 1
			'search'  => $search,
109 1
		]);
110 1
	}
111
112
	/**
113
	 * Show leagues related to the current user
114
	 */
115 3
	public function mine() {
116
		/** @type League|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $leagues_query */
117 3
		$leagues_query = League::query();
118
119
		// Where the user is a player
120
		$leagues_query->whereExists(function (\Illuminate\Database\Query\Builder $query) {
0 ignored issues
show
The method whereExists does only exist in Illuminate\Database\Query\Builder, but not in Illuminate\Database\Eloquent\Builder and League.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
121 3
			$query->select([DB::raw(1)])
122 3
			      ->from('league_teams')
123 3
			      ->join('league_team_user', 'league_teams.id', '=', 'league_team_user.league_team_id')
124 3
			      ->where('league_team_user.user_id', Auth::user()->id)
125 3
			      ->whereRaw('league_teams.league_id = leagues.id');
126 3
		});
127
128
		// Where the user is an admin
129
		$leagues_query->orWhereExists(function (\Illuminate\Database\Query\Builder $query) {
0 ignored issues
show
The method orWhereExists does only exist in Illuminate\Database\Query\Builder, but not in Illuminate\Database\Eloquent\Builder and League.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
130 3
			$query->select([DB::raw(1)])
131 3
			      ->from('league_admins')
132 3
			      ->where('league_admins.user_id', Auth::user()->id)
133 3
			      ->whereRaw('league_admins.league_id = leagues.id');
134 3
		});
135
136 3
		$leagues_query->orderBy('start_date', 'desc');
0 ignored issues
show
The method orderBy does only exist in Illuminate\Database\Query\Builder, but not in Illuminate\Database\Eloquent\Builder and League.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
137 3
		$leagues_query->select('leagues.*');
0 ignored issues
show
The method select does only exist in Illuminate\Database\Query\Builder, but not in Illuminate\Database\Eloquent\Builder and League.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
138 3
		$leagues = $leagues_query->paginate(10);
0 ignored issues
show
The method paginate does only exist in Illuminate\Database\Eloq...\Database\Query\Builder, but not in League.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
139
140
		// Output
141 3
		$this->layout->title = 'My Leagues';
142 3
		$this->layout->content = View::make('league.mine', compact('leagues'));
143 3
	}
144
145
	/**
146
	 * New league validation rules
147
	 * @var array
148
	 */
149
	public $league_valid_rules = [
150
		'name'        => ['required', 'max:255'],
151
		'description' => ['required'],
152
		'url'         => ['url'],
153
		'private'     => ['boolean'],
154
155
		'money'       => ['required', 'integer'],
156
		'units'       => ['required', 'max:16'],
157
		'extra_weeks' => ['required', 'integer', 'between:1,12'],
158
	];
159
160
	/**
161
	 * League creation form
162
	 */
163
	public function create() {
164
165
		$this->layout->title = 'Create league';
166
		$this->layout->content = View::make('league.create', [
167
			'validation_rules' => $this->league_valid_rules,
168
		]);
169
	}
170
171
	/**
172
	 * League creation
173
	 */
174
	public function store() {
175
		$validator = Validator::make(Input::all(), $this->league_valid_rules);
176
		if ($validator->fails()) {
177
			Notification::error('Whoops, something is wrong with your input. Check your errors and try again.');
178
179
			return Redirect::route('league.create')->withInput()->withErrors($validator);
180
		}
181
182
		// Create the league
183
		$league = new League(Input::only([
184
			'name', 'description', 'url', 'money', 'units'
185
		]));
186
		$league->private = Input::get('private') ? true : false;
187
		$league->mode = 'bid';
188
		$league->extra_weeks = Input::get('extra_weeks');
189
		$league->start_date = $league->end_date = Carbon::now()->addWeeks(Config::get('draft.maximum_weeks'));
190
191
		if ($league->save()) {
192
			// Attach current user as league admin
193
			$league->admins()->attach(Auth::user());
194
195
			Notification::success('Your league has been created.');
196
197
			return Redirect::route('league.show', ['league_slug' => $league->slug]);
198
		} else {
199
			Notification::error('Database error, please try again later.');
200
201
			return Redirect::back()->withInput();
202
		}
203
	}
204
205
	/**
206
	 * League page
207
	 *
208
	 * @param League $league
209
	 */
210 1
	public function show(League $league) {
211
		$league->load(['teams', 'teams.users', 'teams.movies' => function($query) {
212
			/** @type LeagueMovie|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query */
213 1
			$query->ordered();
0 ignored issues
show
The method ordered does only exist in LeagueMovie, but not in Illuminate\Database\Eloq...\Database\Query\Builder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
214 1
		}, 'teams.movies.movie', 'teams.movies.latestEarnings']);
215
216
		// Pre-do some work for teams and sort them by earnings
217 1
		$teams = new Collection();
218
219 1
		foreach ($league->teams as $team) {
220
			$earnings = $team->movies->reduce(function ($total, LeagueMovie $movie) {
221 1
				if ($movie->latestEarnings) {
222 1
					return $total + $movie->latestEarnings->domestic;
223
				} else {
224
					return $total;
225
				}
226 1
			}, 0);
227
			$paid_for = $team->movies->reduce(function ($total, LeagueMovie $movie) {
228 1
				return $total + $movie->price;
229 1
			}, 0);
230 1
			$teams->push(compact('team', 'earnings', 'paid_for'));
231 1
		}
232 1
		$teams->sortByDesc('earnings');
233
234 1
		$this->layout->content = View::make('league.show', compact('league', 'teams'));
235 1
		$this->layout->content->show_league_info = true;
236 1
	}
237
	
238
	public function getChartData(League $league) {
239
		$complete = new Collection();
240
		$possible_dates = new Collection();
241
		$startdate = $league->start_date;
0 ignored issues
show
$startdate is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
242
		$enddate = $league->end_date;
243
		$league->load(['teams.movies.movie.earnings' => function($query) {
0 ignored issues
show
The parameter $query 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...
244
		}])->where('movie_earnings.date','<=',$enddate);
245
		
246
		//Find all possible dates first
247
		foreach ($league->teams as $team) {
248
			foreach ($team->movies as $movie) {
249
				foreach ($movie->movie->earnings as $earning){
250
					if($earning->date >= $league->start_date && $earning->date <= $league->end_date) {
251
						$possible_dates->push($earning->date->format("U"));
252
					}
253
				}
254
			}
255
		}
256
		$possible_dates = $possible_dates->unique();
257
		$possible_dates->sortBy(function($role){return $role;});
258
		
259
		//Go through the teams and populate the data
260
		foreach ($league->teams as $team) {
261
			$team_info = new Collection();
262
			$team_earnings = new Collection();
263
			$movies = new Collection();
264
			$complete->push($team_info);
265
			$team_info->put("data",$team_earnings);
266
			$team_info->put("label",$team->name);
267
			$team_info->put("id",$team->id);
268
269
			//Fill actual data for movies now
270
			foreach ($team->movies as $movie) {
271
				foreach ($movie->movie->earnings as $earning){
272
					$mydate = $earning->date->format("U");
273
					if($possible_dates->contains($mydate)) {
274
						$movieinfo = $movies->get($movie->movie->id,new GraphMovie());
275
						$movieinfo->addEarning($mydate,$earning->domestic);
276
						$movies->put($movie->movie->id,$movieinfo);
277
					}
278
				}
279
			}
280
			//Sort movies so we can evaluate gaps
281
			foreach ($movies->values() as $movie) {
282
				$movie->sort();
283
			}
284
			foreach ($possible_dates->values() as $date) {
285
				$item = new Collection();
286
				$item->push($date * 1000); 
287
				$movietotal = 0;
288
				foreach ($movies->values() as $movie) {
289
					$movietotal += $movie->getEarningForDate($date);
290
				}
291
				$item->push($movietotal);
292
				$team_earnings->push($item);
293
			}
294
		}
295
		
296
		return Response::json($complete);
297
	}
298
299
	/**
300
	 * League display based by movies
301
	 *
302
	 * @param League $league
303
	 */
304
	public function showMovies(League $league) {
305
		// Preload data
306
		$league->load(['movies' => function($query) {
307
			/** @type LeagueMovie|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query */
308
			$query->ordered();
0 ignored issues
show
The method ordered does only exist in LeagueMovie, but not in Illuminate\Database\Eloq...\Database\Query\Builder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
309
		}, 'movies.movie', 'movies.latestEarnings', 'movies.teams']);
310
311
		$this->layout->content = View::make('league.show.movies', compact('league'));
312
		$this->layout->content->show_league_info = true;
313
	}
314
}