Passed
Pull Request — master (#5)
by Florian
04:19
created

PhiremockFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findStreamFactoryInterface() 0 8 2
A findRequestFactoryInterface() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mcustiel\Phiremock\Client;
6
7
use Http\Discovery\Psr17FactoryDiscovery;
8
use Mcustiel\Phiremock\Factory as Base;
9
use Psr\Http\Message\RequestFactoryInterface;
10
use Psr\Http\Message\StreamFactoryInterface;
11
12
class PhiremockFactory extends Base
13
{
14
    public function findRequestFactoryInterface(): RequestFactoryInterface
15
    {
16
        if (!class_exists('\Http\Discovery\Psr17FactoryDiscovery', true)) {
17
            throw new \Exception('A psr-17 RequestFactory is needed. '
18
                 . 'Please extend the factory to return a PSR-17 compatible RequestFactoryInterface or install suggested package php-http/discovery');
19
        }
20
21
        return Psr17FactoryDiscovery::findRequestFactory();
22
    }
23
24
    public function findStreamFactoryInterface(): StreamFactoryInterface
25
    {
26
        if (!class_exists('\Http\Discovery\Psr17FactoryDiscovery', true)) {
27
            throw new \Exception('A psr-17 StreamFactory is needed. '
28
                 . 'Please extend the factory to return a PSR-17 compatible StreamFactoryInterface or install suggested package php-http/discovery');
29
        }
30
31
        return Psr17FactoryDiscovery::findStreamFactory();
32
    }
33
}
34