JokeFactory::getRandomJoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Freddymu\ChuckNorrisJokes;
4
5
use GuzzleHttp\Client;
6
7
class JokeFactory
8
{
9
    const API_ENDPOINT = 'https://api.icndb.com/jokes/random';
10
11
    protected $client;
12
13
    public function __construct(Client $client = null)
14
    {
15
        $this->client = $client ?: new Client();
16
    }
17
18
    public function getRandomJoke()
19
    {
20
        $response = $this->client->get(self::API_ENDPOINT);
21
22
        $joke = json_decode($response->getBody()->getContents());
23
24
        return $joke->value->joke;
25
    }
26
}
27