JokeFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 20
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A getRandomJoke() 0 8 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