HockeyController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A getNextGame() 0 17 2
1
<?php namespace WITR\Http\Controllers;
2
3
use WITR\Http\Requests;
4
use WITR\Http\Controllers\Controller;
5
use WITR\RSS\Reader;
6
use WITR\RSS\WomensHockeyParser;
7
use WITR\RSS\MensHockeyParser;
8
9
use Illuminate\Http\Request;
10
use Carbon\Carbon;
11
12
class HockeyController extends Controller {
13
14
	/**
15
	 * Display a listing of the resource.
16
	 *
17
	 * @return Response
18
	 */
19
	public function index()
20
	{
21
		$women = $this->getNextGame(new WomensHockeyParser);
22
		$men = $this->getNextGame(new MensHockeyParser);
23
		return view('hockey.hockey', ['women' => $women, 'men' => $men]);
24
	}
25
26
	private function getNextGame($parser)
27
	{
28
		$reader = Reader::forParser($parser);
29
		$games = $reader->get()->sortBy(function($game) {
30
			return $game->startUtc->timestamp;
31
		});
32
		$laterGames = $games->filter(function ($game) {
33
			return $game->startUtc > Carbon::now('UTC');
34
		});
35
36
		if ($laterGames->isEmpty())
37
		{
38
			return $games->last();
39
		}
40
41
		return $laterGames->first();
42
	}
43
}
44