Passed
Push — master ( f3b94d...fdd73f )
by nicolas
01:01
created

DekaleeClient::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 14
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 2
1
<?php
2
3
namespace Dekalee\MailjetBundle\Client;
4
5
use Mailjet\Client;
6
use Mailjet\Response;
7
8
/**
9
 * Class DekaleeClient
10
 */
11
class DekaleeClient extends Client
12
{
13
    protected $calls = [];
14
15
    /**
16
     * Trigger a POST request
17
     *
18
     * @param array $resource Mailjet Resource/Action pair
19
     * @param array $args     Request arguments
20
     *
21
     * @return Response
22
     */
23 View Code Duplication
    public function post($resource, $args = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $response = parent::post($resource, $args);
26
27
        $this->calls[] = [
28
            'method' => 'POST',
29
            'resource' => $resource,
30
            'args' => $args,
31
            'success' => $response->success(),
32
            'response' => $response->getBody(),
33
        ];
34
35
        return $response;
36
    }
37
38
    /**
39
     * Trigger a GET request
40
     *
41
     * @param array $resource Mailjet Resource/Action pair
42
     * @param array $args     Request arguments
43
     *
44
     * @return Response
45
     */
46 View Code Duplication
    public function get($resource, $args = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $response = parent::get($resource, $args);
49
50
        $this->calls[] = [
51
            'method' => 'GET',
52
            'resource' => $resource,
53
            'args' => $args,
54
            'success' => $response->success(),
55
            'response' => $response->getBody(),
56
        ];
57
58
        return $response;
59
    }
60
61
    /**
62
     * Trigger a POST request
63
     *
64
     * @param array $resource Mailjet Resource/Action pair
65
     * @param array $args     Request arguments
66
     *
67
     * @return Response
68
     */
69 View Code Duplication
    public function put($resource, $args = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $response = parent::put($resource, $args);
72
73
        $this->calls[] = [
74
            'method' => 'PUT',
75
            'resource' => $resource,
76
            'args' => $args,
77
            'success' => $response->success(),
78
            'response' => $response->getBody(),
79
        ];
80
81
        return $resource;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $resource; (array) is incompatible with the return type of the parent method Mailjet\Client::put of type Mailjet\Response.

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 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('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...
82
    }
83
84
    /**
85
     * Trigger a GET request
86
     *
87
     * @param array $resource Mailjet Resource/Action pair
88
     * @param array $args     Request arguments
89
     *
90
     * @return Response
91
     */
92 View Code Duplication
    public function delete($resource, $args = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
    {
94
        $response = parent::delete($resource, $args);
95
96
        $this->calls[] = [
97
            'method' => 'DELETE',
98
            'resource' => $resource,
99
            'args' => $args,
100
            'success' => $response->success(),
101
            'response' => $response->getBody(),
102
        ];
103
104
        return $response;
105
    }
106
107
    /**
108
     * @return array
109
     */
110
    public function getCalls()
111
    {
112
        return $this->calls;
113
    }
114
}
115