Completed
Push — master ( c985f8...7064aa )
by Kazi Mainuddin
03:41
created

AbstractVerifier::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Tzsk\Payu\Verifiers;
4
5
use GuzzleHttp\Client;
6
use Tzsk\Payu\Helpers\Config;
7
use Illuminate\Http\Request;
8
use Tzsk\Payu\Helpers\Processor;
9
use Tzsk\Payu\Model\PayuPayment;
10
11
abstract class AbstractVerifier
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $txnIds = [];
17
18
    /**
19
     * @var Client
20
     */
21
    protected $config;
22
23
    /**
24
     * @param array $transaction_ids
25
     * @param string $account
26
     */
27
    public function __construct($transaction_ids, $account = null)
28
    {
29
        $this->txnIds = $transaction_ids;
30
        $this->config = new Config($account);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Tzsk\Payu\Helpers\Config($account) of type object<Tzsk\Payu\Helpers\Config> is incompatible with the declared type object<GuzzleHttp\Client> of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31
        $this->client = new Client();
0 ignored issues
show
Bug introduced by
The property client 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...
32
    }
33
34
    /**
35
     * @param object $data
36
     * @return PayuPayment
37
     */
38
    protected function getInstance($data)
39
    {
40
        $request = new Request((array) $data);
41
        $attributes = (new Processor($request))->process();
42
43
        if($this->config->getDriver() == 'database') {
44
            return PayuPayment::find($attributes);
45
        }
46
47
        return new PayuPayment($attributes);
48
    }
49
50
    /**
51
     * @return object
52
     */
53
    abstract public function verify();
54
}
55