Completed
Pull Request — master (#34)
by Márk
02:59
created

MessageFactoryDiscovery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 37.5%

Importance

Changes 8
Bugs 2 Features 1
Metric Value
wmc 2
c 8
b 2
f 1
lcom 0
cbo 2
dl 22
loc 22
ccs 3
cts 8
cp 0.375
rs 10

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\Message\MessageFactory;
6
7
/**
8
 * Finds a Message Factory.
9
 *
10
 * @author Márk Sági-Kazár <[email protected]>
11
 */
12 View Code Duplication
final class MessageFactoryDiscovery extends ClassDiscovery
13
{
14
    /**
15
     * Finds a Message Factory.
16
     *
17
     * @return MessageFactory
18
     */
19 1
    public static function find()
20
    {
21
        try {
22 1
            $messageFactory = static::findOneByType('Http\Message\MessageFactory');
23
24 1
            return new $messageFactory();
25
        } catch (NotFoundException $e) {
26
            throw new NotFoundException(
27
                'No factories found. Install php-http/message to use Guzzle or Diactoros factories.',
28
                0,
29
                $e
30
            );
31
        }
32
    }
33
}
34