JokeFactory::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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