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

MessageFactoryDiscovery::find()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 14
loc 14
rs 9.4285
ccs 7
cts 7
cp 1
cc 2
eloc 9
nc 3
nop 0
crap 2
1
<?php
2
3
namespace Http\Discovery;
4
5
use Http\Discovery\Exception\DiscoveryFailedException;
6
use Http\Discovery\Exception\NotFoundException;
7
use Http\Message\MessageFactory;
8
9
/**
10
 * Finds a Message Factory.
11
 *
12
 * @author Márk Sági-Kazár <[email protected]>
13
 */
14 View Code Duplication
final class MessageFactoryDiscovery extends ClassDiscovery
15
{
16
    /**
17
     * Finds a Message Factory.
18
     *
19
     * @return MessageFactory
20
     *
21
     * @throws NotFoundException
22
     */
23 1
    public static function find()
24
    {
25
        try {
26
            $messageFactory = static::findOneByType(MessageFactory::class);
27
28 1
            return new $messageFactory();
29 1
        } catch (DiscoveryFailedException $e) {
30 1
            throw new NotFoundException(
31 1
                'No message 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