Completed
Push — master ( 4306e3...de53c0 )
by Mahmoud
03:52
created

PaymentsProxy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A charge() 0 13 3
A chargeWithStripe() 0 4 2
A chargeWithPaypal() 0 4 1
1
<?php
2
3
namespace App\Ship\Features\Payment\Proxies;
4
5
use App\Containers\Stripe\Tasks\ChargeWithStripeTask;
6
use App\Ship\Features\Payment\Contracts\ChargeableInterface;
7
use Illuminate\Support\Facades\App;
8
9
/**
10
 * Class PaymentsProxy.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class PaymentsProxy
15
{
16
17
    /**
18
     * @param \App\Ship\Features\Payment\Contracts\ChargeableInterface $object
19
     * @param                                                          $amount
20
     * @param                                                          $currency
21
     * @param null                                                     $paymentMethod
22
     *
23
     * @return  mixed
24
     */
25
    public function charge(ChargeableInterface $object, $amount, $currency, $paymentMethod = null)
26
    {
27
        if (!$paymentMethod) {
28
            $paymentMethod = $this->chargeWithStripe($object);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $paymentMethod is correct as $this->chargeWithStripe($object) (which targets App\Ship\Features\Paymen...oxy::chargeWithStripe()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
29
        }
30
31
        if (!$paymentMethod) {
32
            $paymentMethod = $this->chargeWithPaypal($object);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $paymentMethod is correct as $this->chargeWithPaypal($object) (which targets App\Ship\Features\Paymen...oxy::chargeWithPaypal()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
33
        }
34
35
        // run the right task for the available method
36
        return $paymentMethod->run($object, $amount, $currency);
0 ignored issues
show
Bug introduced by
The method run cannot be called on $paymentMethod (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
37
    }
38
39
    /**
40
     * @param $object
41
     *
42
     * @return  null
43
     */
44
    private function chargeWithStripe($object)
45
    {
46
        return $object->stripeAccount ? App::make(ChargeWithStripeTask::class) : null;
47
    }
48
49
    /**
50
     * @param $object
51
     *
52
     * @return  null
53
     */
54
    private function chargeWithPaypal($object)
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        return null; // TODO: to be implemented once a Paypal container is ready
57
    }
58
59
}
60