UpdateLeagueMovieEarnings::fire()   B
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 13
cp 0
rs 8.7624
c 0
b 0
f 0
cc 5
eloc 10
nc 2
nop 2
crap 30
1
<?php
2
3
use Illuminate\Queue\Jobs\Job;
4
5
class UpdateLeagueMovieEarnings {
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...
6
7
8
	/**
9
	 * Update LeagueMovie with the latest earnings if applicable
10
	 *
11
	 * @param Job $job
12
	 * @param     $data
13
	 */
14
	public function fire(Job $job, $data) {
15
16
		/** @type LeagueMovie $leagueMovie */
17
		$leagueMovie = LeagueMovie::findOrFail($data['league_movie_id']);
18
		/** @type MovieEarning $earnings */
19
		$earnings = MovieEarning::findOrFail($data['earnings_id']);
20
21
		if ( // Sanity checks
22
			$leagueMovie->movie_id == $earnings->movie_id
23
			&& $leagueMovie->league->end_date > $earnings->date
24
			&& (! $leagueMovie->latestEarnings || $leagueMovie->latestEarnings->date < $earnings->date)
25
		) {
26
			$leagueMovie->latest_earnings_id = $earnings->id;
27
			$leagueMovie->save();
28
29
			// Possibly TODO: Update team's total earnings if that gets cached
30
		}
31
32
		$job->delete();
33
34
	}
35
}