Completed
Push — master ( 2ec2e2...476664 )
by Joachim
05:23
created

CallbackFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 16 3
1
<?php
2
3
namespace Loevgaard\AltaPay\Callback;
4
5
use Loevgaard\AltaPay\Callback\Form as FormCallback;
6
use Loevgaard\AltaPay\Callback\Redirect as RedirectCallback;
7
use Loevgaard\AltaPay\Callback\Xml as XmlCallback;
8
use Psr\Http\Message\ServerRequestInterface;
9
10
class CallbackFactory
11
{
12
    /**
13
     * Will take a Psr Server Request and return a Form, Xml or Redirect
14
     * callback object that represent the actual callback
15
     *
16
     * @param ServerRequestInterface $request
17
     * @throws \InvalidArgumentException
18
     * @return CallbackInterface
19
     */
20 12
    public function create(ServerRequestInterface $request) : CallbackInterface
21
    {
22
        $callbacks = [
23 12
            XmlCallback::class,
24
            FormCallback::class,
25
            RedirectCallback::class
26
        ];
27
28 12
        foreach ($callbacks as $callback) {
29 12
            if (call_user_func([$callback, 'initable'], $request)) {
30 12
                return new $callback($request);
31
            }
32
        }
33
34 3
        throw new \InvalidArgumentException('A callback could not be instantiated');
35
    }
36
}
37