Inbounder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A newHandlerInstanceFor() 0 8 2
A gateway() 0 4 1
1
<?php
2
3
namespace Inbounder;
4
5
use Illuminate\Http\Request;
6
use Inbounder\Exceptions\UndefinedGatewayException;
7
8
class Inbounder
9
{
10
    /**
11
     * Class constructor.
12
     *
13
     * @param App $app
14
     */
15
    public function __construct($app)
16
    {
17
        $this->app = $app;
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
    }
19
20
    /**
21
     * Create a new instance handler for the given gateway.
22
     *
23
     * @param string $name
24
     *
25
     * @return AbstractHandler
26
     */
27
    protected function newHandlerInstanceFor($name)
28
    {
29
        if (!$handler = config('inbounder.gateways.'.$name)) {
30
            throw new UndefinedGatewayException('The gateway \''.$name.'\' is not defined');
31
        }
32
33
        return $this->app->make($handler);
34
    }
35
36
    /**
37
     * Return an instance of the gateway manager.
38
     *
39
     * @param string  $gateway
40
     * @param Request $request
41
     *
42
     * @return GatewayManager
43
     */
44
    public function gateway($gateway, Request $request)
45
    {
46
        return new GatewayManager($this->newHandlerInstanceFor($gateway), $request);
47
    }
48
}
49