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/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

src/HttpClientDiscovery.php 1 location

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

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