NowPlayingViewComposer::compose()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4286
cc 2
eloc 11
nc 3
nop 1
1
<?php
2
3
namespace WITR\ViewComposers;
4
5
use WITR\AlbumReview;
6
use Illuminate\View\View;
7
use GuzzleHttp\Client;
8
use GuzzleHttp\Exception\RequestException;
9
use stdClass;
10
11
class NowPlayingViewComposer {
12
13
	/**
14
	 * Bind data to the view.
15
	 *
16
	 * @param  View  $view
17
	 * @return void
18
	 */
19
	public function compose(View $view)
20
	{
21
        $client = new Client();
22
        try {
23
			$response = $client->get('http://logger.witr.rit.edu/latest.json', [
24
				'timeout' => 1,
25
			]);
26
			return $view->with('nowplaying', $response->json(['object' => true]));
27
		} catch (RequestException $e) {
28
			$data = new stdClass;
29
			$data->artist = '';
30
			$data->title = 'Not Available';
31
			return $view->with('nowplaying', $data);
32
		}
33
	}
34
}