FakePaymentGateway::chargeAmountForPayable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 4
1
<?php
2
3
namespace SanderVanHooft\PayableRedirect;
4
5
use Illuminate\Database\Eloquent\Model;
6
use SanderVanHooft\PayableRedirect\Payment;
7
8
class FakePaymentGateway implements PaymentGateway
9
{
10
    /**
11
     * @param  Int
12
     * @param  Illuminate\Database\Eloquent\Model
13
     * @return Payment
14
     */
15
    public function chargeAmountForPayable(
16
        Int $amount,
17
        Model $payable,
18
        String $description,
19
        array $params = []
20
    ) : Payment {
21
        $payment = $payable->payments()->create([
22
            'amount' => $amount,
23
            'status' => 'open',
24
            'description' => $description,
25
            'redirect_url' => 'https://www.fake-payment-gateway-url.com/?ref=123456',
26
            'return_url' => $params['return_url'],
27
            'gateway_name' => $this->getGatewayName(),
28
            'gateway_payment_reference' => 'fake-reference',
29
        ]);
30
31
        return $payment;
32
    }
33
34
    /**
35
     * @return String
36
     */
37
    public function getGatewayName() : String
38
    {
39
        return self::class;
40
    }
41
42
    /**
43
     * @param  Payment
44
     * @return Payment
45
     */
46
    public function fetchUpdateFor(Payment $payment) : Payment
47
    {
48
        $payment->status = 'paid';
49
        $payment->redirect_url = null;
0 ignored issues
show
Documentation introduced by
The property redirect_url does not exist on object<SanderVanHooft\PayableRedirect\Payment>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
50
        $payment->save();
51
        return $payment;
52
    }
53
}
54