Psr18ClientDiscovery   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 20
loc 20
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A find() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Http\Discovery;
4
5
use Http\Discovery\Exception\DiscoveryFailedException;
6
use Psr\Http\Client\ClientInterface;
7
8
/**
9
 * Finds a PSR-18 HTTP Client.
10
 *
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13 View Code Duplication
final class Psr18ClientDiscovery extends ClassDiscovery
14
{
15
    /**
16
     * Finds a PSR-18 HTTP Client.
17
     *
18
     * @return ClientInterface
19
     *
20
     * @throws Exception\NotFoundException
21
     */
22
    public static function find()
23
    {
24
        try {
25
            $client = static::findOneByType(ClientInterface::class);
26
        } catch (DiscoveryFailedException $e) {
27
            throw new \Http\Discovery\Exception\NotFoundException('No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle6-adapter".', 0, $e);
28
        }
29
30
        return static::instantiateClass($client);
31
    }
32
}
33