Code Duplication    Length = 24-24 lines in 6 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

@@ 15-38 (lines=24) @@
12
 *
13
 * @deprecated This will be removed in 2.0. Consider using Psr17FactoryDiscovery.
14
 */
15
final class MessageFactoryDiscovery extends ClassDiscovery
16
{
17
    /**
18
     * Finds a Message Factory.
19
     *
20
     * @return MessageFactory
21
     *
22
     * @throws Exception\NotFoundException
23
     */
24
    public static function find()
25
    {
26
        try {
27
            $messageFactory = static::findOneByType(MessageFactory::class);
28
        } catch (DiscoveryFailedException $e) {
29
            throw new NotFoundException(
30
                'No message factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.',
31
                0,
32
                $e
33
            );
34
        }
35
36
        return static::instantiateClass($messageFactory);
37
    }
38
}
39

src/StreamFactoryDiscovery.php 1 location

@@ 15-38 (lines=24) @@
12
 *
13
 * @deprecated This will be removed in 2.0. Consider using Psr17FactoryDiscovery.
14
 */
15
final class StreamFactoryDiscovery extends ClassDiscovery
16
{
17
    /**
18
     * Finds a Stream Factory.
19
     *
20
     * @return StreamFactory
21
     *
22
     * @throws Exception\NotFoundException
23
     */
24
    public static function find()
25
    {
26
        try {
27
            $streamFactory = static::findOneByType(StreamFactory::class);
28
        } catch (DiscoveryFailedException $e) {
29
            throw new NotFoundException(
30
                'No stream factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.',
31
                0,
32
                $e
33
            );
34
        }
35
36
        return static::instantiateClass($streamFactory);
37
    }
38
}
39

src/UriFactoryDiscovery.php 1 location

@@ 15-38 (lines=24) @@
12
 *
13
 * @deprecated This will be removed in 2.0. Consider using Psr17FactoryDiscovery.
14
 */
15
final class UriFactoryDiscovery extends ClassDiscovery
16
{
17
    /**
18
     * Finds a URI Factory.
19
     *
20
     * @return UriFactory
21
     *
22
     * @throws Exception\NotFoundException
23
     */
24
    public static function find()
25
    {
26
        try {
27
            $uriFactory = static::findOneByType(UriFactory::class);
28
        } catch (DiscoveryFailedException $e) {
29
            throw new NotFoundException(
30
                'No uri factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.',
31
                0,
32
                $e
33
            );
34
        }
35
36
        return static::instantiateClass($uriFactory);
37
    }
38
}
39

src/Psr18ClientDiscovery.php 1 location

@@ 13-36 (lines=24) @@
10
 *
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13
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(
28
                'No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle6-adapter".',
29
                0,
30
                $e
31
            );
32
        }
33
34
        return static::instantiateClass($client);
35
    }
36
}
37