Completed
Push — master ( fac124...ff4c77 )
by Márk
10s
created

UriFactoryDiscovery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 2 Features 2
Metric Value
wmc 2
c 7
b 2
f 2
lcom 0
cbo 2
dl 24
loc 24
rs 10
ccs 7
cts 7
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A find() 14 14 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 Http\Discovery\Exception\NotFoundException;
7
use Http\Message\UriFactory;
8
9
/**
10
 * Finds a URI Factory.
11
 *
12
 * @author David de Boer <[email protected]>
13
 */
14 View Code Duplication
final class UriFactoryDiscovery extends ClassDiscovery
15
{
16
    /**
17
     * Finds a URI Factory.
18
     *
19
     * @return UriFactory
20
     *
21
     * @throws NotFoundException
22
     */
23 1
    public static function find()
24
    {
25
        try {
26
            $uriFactory = static::findOneByType(UriFactory::class);
27
28 1
            return new $uriFactory();
29 1
        } catch (DiscoveryFailedException $e) {
30 1
            throw new NotFoundException(
31 1
                'No uri factories found. To use Guzzle or Diactoros factories install php-http/message and the chosen message implementation.',
32 1
                0,
33
                $e
34 1
            );
35
        }
36
    }
37
}
38