Code Duplication    Length = 24-24 lines in 5 locations

src/HttpAsyncClientDiscovery.php 1 location

@@ 13-36 (lines=24) @@
10
 *
11
 * @author Joel Wurtz <[email protected]>
12
 */
13
final class HttpAsyncClientDiscovery extends ClassDiscovery
14
{
15
    /**
16
     * Finds an HTTP Async Client.
17
     *
18
     * @return HttpAsyncClient
19
     *
20
     * @throws Exception\NotFoundException
21
     */
22
    public static function find()
23
    {
24
        try {
25
            $asyncClient = static::findOneByType(HttpAsyncClient::class);
26
        } catch (DiscoveryFailedException $e) {
27
            throw new NotFoundException(
28
                'No HTTPlug async clients found. Make sure to install a package providing "php-http/async-client-implementation". Example: "php-http/guzzle6-adapter".',
29
                0,
30
                $e
31
            );
32
        }
33
34
        return static::instantiateClass($asyncClient);
35
    }
36
}
37

src/HttpClientDiscovery.php 1 location

@@ 13-36 (lines=24) @@
10
 *
11
 * @author Márk Sági-Kazár <[email protected]>
12
 */
13
final class HttpClientDiscovery extends ClassDiscovery
14
{
15
    /**
16
     * Finds an HTTP Client.
17
     *
18
     * @return HttpClient
19
     *
20
     * @throws Exception\NotFoundException
21
     */
22
    public static function find()
23
    {
24
        try {
25
            $client = static::findOneByType(HttpClient::class);
26
        } catch (DiscoveryFailedException $e) {
27
            throw new NotFoundException(
28
                'No HTTPlug clients found. Make sure to install a package providing "php-http/client-implementation". Example: "php-http/guzzle6-adapter".',
29
                0,
30
                $e
31
            );
32
        }
33
34
        return static::instantiateClass($client);
35
    }
36
}
37

src/MessageFactoryDiscovery.php 1 location

@@ 13-36 (lines=24) @@
10
 *
11
 * @author Márk Sági-Kazár <[email protected]>
12
 */
13
final class MessageFactoryDiscovery extends ClassDiscovery
14
{
15
    /**
16
     * Finds a Message Factory.
17
     *
18
     * @return MessageFactory
19
     *
20
     * @throws Exception\NotFoundException
21
     */
22
    public static function find()
23
    {
24
        try {
25
            $messageFactory = static::findOneByType(MessageFactory::class);
26
        } catch (DiscoveryFailedException $e) {
27
            throw new NotFoundException(
28
                'No message factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.',
29
                0,
30
                $e
31
            );
32
        }
33
34
        return static::instantiateClass($messageFactory);
35
    }
36
}
37

src/StreamFactoryDiscovery.php 1 location

@@ 13-36 (lines=24) @@
10
 *
11
 * @author Михаил Красильников <[email protected]>
12
 */
13
final class StreamFactoryDiscovery extends ClassDiscovery
14
{
15
    /**
16
     * Finds a Stream Factory.
17
     *
18
     * @return StreamFactory
19
     *
20
     * @throws Exception\NotFoundException
21
     */
22
    public static function find()
23
    {
24
        try {
25
            $streamFactory = static::findOneByType(StreamFactory::class);
26
        } catch (DiscoveryFailedException $e) {
27
            throw new NotFoundException(
28
                'No stream factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.',
29
                0,
30
                $e
31
            );
32
        }
33
34
        return static::instantiateClass($streamFactory);
35
    }
36
}
37

src/UriFactoryDiscovery.php 1 location

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