NowPlayingViewComposer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A compose() 0 15 2
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
}