JokeFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRandomJoke() 0 7 1
A __construct() 0 3 2
1
<?php
2
3
namespace Ejdelmonico\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