App\services\Lastfm::getArtistInfo PHP Méthode

getArtistInfo() public méthode

Get information about an artist.
public getArtistInfo ( $name ) : array | false
$name string Name of the artist
Résultat array | false
    public function getArtistInfo($name)
    {
        if (!$this->enabled()) {
            return false;
        }
        $name = urlencode($name);
        try {
            $cacheKey = md5("lastfm_artist_{$name}");
            if ($response = Cache::get($cacheKey)) {
                $response = simplexml_load_string($response);
            } else {
                if ($response = $this->get("?method=artist.getInfo&autocorrect=1&artist={$name}")) {
                    Cache::put($cacheKey, $response->asXML(), 24 * 60 * 7);
                }
            }
            $response = json_decode(json_encode($response), true);
            if (!$response || !($artist = array_get($response, 'artist'))) {
                return false;
            }
            return ['url' => array_get($artist, 'url'), 'image' => count($artist['image']) > 3 ? $artist['image'][3] : $artist['image'][0], 'bio' => ['summary' => $this->formatText(array_get($artist, 'bio.summary')), 'full' => $this->formatText(array_get($artist, 'bio.content'))]];
        } catch (Exception $e) {
            Log::error($e);
            return false;
        }
    }

Usage Example

 public function testGetArtistInfoFailed()
 {
     $client = m::mock(Client::class, ['get' => new Response(400, [], file_get_contents(dirname(__FILE__) . '/blobs/lastfm/artist-notfound.xml'))]);
     $api = new Lastfm(null, null, $client);
     $this->assertFalse($api->getArtistInfo('foo'));
 }