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.

CreateChargeRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 51
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getEndpoint() 0 4 1
A getRequestMethod() 0 4 1
A getPayload() 0 4 1
1
<?php
2
3
namespace CMPayments\PaymentSdk\Requests;
4
5
use CMPayments\PaymentSdk\Entities\Charge;
6
use CMPayments\PaymentSdk\Gateway;
7
use Money\Currencies\ISOCurrencies;
8
use Money\Money;
9
10
/**
11
 * Class CreateChargeRequest
12
 *
13
 * @package CMPayments\PaymentSdk
14
 * @author  Michel Westerink <[email protected]>
15
 */
16
class CreateChargeRequest implements RequestInterface
17
{
18
    /**
19
     * Default endpoint (Uri in Guzzle context)
20
     */
21
    const ENDPOINT = 'charges/v1';
22
    /**
23
     * @var Charge
24
     */
25
    private $charge;
26
27
    /**
28
     * CreateChargeRequest constructor.
29
     */
30 3
    public function __construct(Charge $charge)
31
    {
32 3
        $this->charge = $charge;
33 3
    }
34
35
36
    /**
37
     * Return the uri
38
     *
39
     * @return string The uri
40
     */
41 1
    public function getEndpoint()
42
    {
43 1
        return self::ENDPOINT;
44
    }
45
46
    /**
47
     * Return request method
48
     *
49
     * @return string This is the request type
50
     */
51 1
    public function getRequestMethod()
52
    {
53 1
        return Gateway::REQUEST_METHOD_POST;
54
    }
55
56
57
    /**
58
     * Retrieve the whole request
59
     *
60
     * @return string[] The complete request
61
     */
62 1
    public function getPayload()
63
    {
64 1
        return $this->charge->toArray();
0 ignored issues
show
Best Practice introduced by
The expression return $this->charge->toArray(); seems to be an array, but some of its elements' types (integer|double|Money\Currency) are incompatible with the return type declared by the interface CMPayments\PaymentSdk\Re...stInterface::getPayload of type array[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
65
    }
66
}
67