GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PayUz::validateModel()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.6111
c 0
b 0
f 0
cc 5
nc 4
nop 3
1
<?php
2
3
namespace Goodoneuz\PayUz;
4
5
use Illuminate\Support\Facades\View;
6
use Goodoneuz\PayUz\Models\Transaction;
7
use Goodoneuz\PayUz\Models\PaymentSystem;
8
use Goodoneuz\PayUz\Http\Classes\Payme\Payme;
9
use Goodoneuz\PayUz\Http\Classes\Click\Click;
10
use Goodoneuz\PayUz\Http\Classes\Paynet\Paynet;
11
use Goodoneuz\PayUz\Http\Classes\Stripe\Stripe;
12
use Goodoneuz\PayUz\Http\Classes\PaymentException;
13
14
class PayUz
15
{
16
17
    protected $driverClass = null;
18
19
    /**
20
     * PayUz constructor.
21
     */
22
    public function __construct()
23
    {
24
    }
25
26
27
    /**
28
     * Select payment driver
29
     * @param null $driver
30
     * @return $this
31
     */
32
    public function driver($driver = null){
33
        switch ($driver){
34
            case PaymentSystem::PAYME:
35
                $this->driverClass = new Payme;
36
                break;
37
            case PaymentSystem::CLICK:
38
                $this->driverClass = new Click;
39
                break;
40
            case PaymentSystem::PAYNET:
41
                $this->driverClass = new Paynet;
42
                break;
43
            case PaymentSystem::STRIPE:
44
                $this->driverClass = new Stripe;
45
                break;
46
        }
47
        return $this;
48
    }
49
50
    /**
51
     * Redirect to payment system
52
     * @param $model
53
     * @param $amount
54
     * @param int $currency_code
55
     * @return PayUz
56
     * @throws \Exception
57
     */
58
    public function redirect($model, $amount, $currency_code = Transaction::CURRENCY_CODE_UZS, $url = null){
59
        $this->validateDriver();
60
        $driver = $this->driverClass;
61
        $params = $driver->getRedirectParams($model, $amount, $currency_code, $url);
0 ignored issues
show
Bug introduced by
The method getRedirectParams does only exist in Goodoneuz\PayUz\Http\Cla...p\Classes\Stripe\Stripe, but not in Goodoneuz\PayUz\Http\Classes\Paynet\Paynet.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
62
        $view = 'pay-uz::merchant.index';
63
        if (!empty($driver::CUSTOM_FORM))
64
            $view = $driver::CUSTOM_FORM;
65
        echo view($view, compact('params'));
66
    }
67
68
    /**
69
     * @return $this
70
     * @throws \Exception
71
     */
72
    public function handle(){
73
        $this->validateDriver();
74
        try{
75
            return $this->driverClass->run();
76
        }catch(PaymentException $e){
77
            return $e->response();
78
        }
79
80
        return $this;
0 ignored issues
show
Unused Code introduced by
return $this; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
81
    }
82
83
    /**
84
     * @param $model
85
     * @param $amount
86
     * @param $currency_code
87
     * @throws \Exception
88
     */
89
    public function validateModel($model, $amount, $currency_code){
90
        if (is_null($model))
91
            throw new \Exception('Modal can\'t be null');
92
        if (is_null($amount) || $amount == 0)
93
            throw new \Exception('Amount can\'t be null or 0');
94
        if (is_null($currency_code))
95
            throw new \Exception('Currency code can\'t be null');
96
    }
97
98
    /**
99
     * @throws \Exception
100
     */
101
    public function validateDriver(){
102
        if (is_null($this->driverClass))
103
            throw new \Exception('Driver not selected');
104
    }
105
}
106