Completed
Push — master ( dd0453...7030c1 )
by Edgar
02:30
created

Inbounder::newHandlerInstanceFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Inbounder;
4
5
use Illuminate\Http\Request;
6
use Inbounder\GatewayManager;
7
use Inbounder\Exceptions\UndefinedGatewayException;
8
9
class Inbounder
10
{
11
    /**
12
     * Class constructor
13
     * 
14
     * @param App $app
15
     */
16
    public function __construct($app)
17
    {
18
        $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...
19
    }
20
21
    /**
22
     * Create a new instance handler for the given gateway
23
     * 
24
     * @param String $name
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
        return $this->app->make($handler);
33
    }
34
35
    /**
36
     * Return an instance of the gateway manager
37
     * 
38
     * @param String $gateway
39
     * @param Request $request
40
     * @return GatewayManager
41
     */
42
    public function gateway($gateway, Request $request)
43
    {
44
        return new GatewayManager($this->newHandlerInstanceFor($gateway), $request);
45
    }
46
}
47