Completed
Push — 1.0.x-dev ( 34a83d...bde745 )
by Felix
18s queued 11s
created

RequestAdapterFactory::create()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.7998
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4
1
<?php declare(strict_types=1);
2
3
namespace Starlit\Request\Authenticator\Hmac\Adapter;
4
5
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
6
use Psr\Http\Message\RequestInterface as Psr7Request;
7
use GuzzleHttp\Message\Request as Guzzle5Request;
8
9
class RequestAdapterFactory implements RequestAdapterFactoryInterface
10
{
11 4
    public function create($request): RequestAdapterInterface
12
    {
13 4
        if ($request instanceof Psr7Request) {
14 1
            return new Psr7RequestAdapter($request);
15 3
        } elseif ($request instanceof SymfonyRequest) {
16 1
            return new SymfonyRequestAdapter($request);
17 2
        } elseif ($request instanceof Guzzle5Request) {
18 1
            return new Guzzle5RequestAdapter($request);
19
        } else {
20 1
            throw new \InvalidArgumentException(
21 1
                'Request type not supported. Only PSR-7, Symfony or Guzzle5 requests are supported.'
22
            );
23
        }
24
    }
25
}
26