UpdateLeagueMovieEarnings   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 31
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B fire() 0 21 5
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
}