LastFmController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests;
6
use Dandelionmood\LastFm\LastFm;
7
8
class LastFmController extends Controller
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $sampleArtist = ['artist' => 'The Pierces'];
14
15
    /**
16
     * LastFm Object
17
     * @var object;
18
     */
19
    protected $lastfm;
20
21
    /**
22
     * Initialize the Controller with necessary arguments
23
     */
24
    public function __construct()
25
    {
26
        $this->lastfm = new LastFm(env('LASTFM_API_KEY'), env('LASTFM_API_SECRET'));
27
    }
28
29
    /**
30
     * Return all tweets to the LastFM API dashboard
31
     * @return mixed
32
     */
33
    public function getPage()
34
    {
35
        $details = $this->getArtistInfo();
36
37
        $albums = array_slice($this->getTopAlbums(), 0, 4);
38
39
        $tracks = array_slice($this->getTopTracks(), 0, 10);
40
41
        return view('api.lastfm')->withDetails($details)
42
                                 ->withAlbums($albums)
43
                                 ->withTracks($tracks);
44
    }
45
46
    /**
47
     * Get Artist Info
48
     * @return array
49
     */
50
    private function getArtistInfo()
51
    {
52
        $result = (array)$this->lastfm->artist_getInfo($this->sampleArtist);
53
54
        return $result['artist'];
55
    }
56
57
    /**
58
     * Get Top Albums
59
     * @return array
60
     */
61
    private function getTopAlbums()
62
    {
63
        $result = (array)$this->lastfm->artist_getTopAlbums($this->sampleArtist);
64
65
        return $result['topalbums']->album;
66
    }
67
68
    /**
69
     * Get Top Tracks
70
     * @return array
71
     */
72
    private function getTopTracks()
73
    {
74
        $result = (array)$this->lastfm->artist_getTopTracks($this->sampleArtist);
75
76
        return $result['toptracks']->track;
77
    }
78
}
79