Inbounder::gateway()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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