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.
Completed
Push — master ( b7696d...79d94c )
by Carlos
04:27 queued 01:59
created

Message::getMessageType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/easy-sms.
5
 * (c) overtrue <[email protected]>
6
 * This source file is subject to the MIT license that is bundled
7
 * with this source code in the file LICENSE.
8
 */
9
10
namespace Overtrue\EasySms;
11
12
use Overtrue\EasySms\Contracts\MessageInterface;
13
14
/**
15
 * Class Message.
16
 */
17
class Message implements MessageInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $gateways = [];
23
24
    /**
25
     * @var string
26
     */
27
    protected $type;
28
29
    /**
30
     * @var string
31
     */
32
    protected $content;
33
34
    /**
35
     * @var string
36
     */
37
    protected $template;
38
39
    /**
40
     * @var array
41
     */
42
    protected $data = [];
43
44
    /**
45
     * Message constructor.
46
     *
47
     * @param array  $attributes
48
     * @param string $type
49
     */
50
    public function __construct(array $attributes = [], $type = MessageInterface::TEXT_MESSAGE)
51
    {
52
        $this->type = $type;
53
54
        foreach ($attributes as $property => $value) {
55
            if (property_exists($this, $property)) {
56
                $this->$property = $value;
57
            }
58
        }
59
    }
60
61
    /**
62
     * Return the message type.
63
     *
64
     * @return string
65
     */
66
    public function getMessageType()
67
    {
68
        return $this->type;
69
    }
70
71
    /**
72
     * Return message content.
73
     *
74
     * @return string
75
     */
76
    public function getContent()
77
    {
78
        return $this->content;
79
    }
80
81
    /**
82
     * Return the template id of message.
83
     *
84
     * @return string
85
     */
86
    public function getTemplate()
87
    {
88
        return $this->template;
89
    }
90
91
    /**
92
     * @param string $type
93
     *
94
     * @return $this
95
     */
96
    public function setType(string $type)
97
    {
98
        $this->type = $type;
99
100
        return $this;
101
    }
102
103
    /**
104
     * @param mixed $content
105
     *
106
     * @return $this
107
     */
108
    public function setContent($content)
109
    {
110
        $this->content = $content;
111
112
        return $this;
113
    }
114
115
    /**
116
     * @param mixed $template
117
     *
118
     * @return $this
119
     */
120
    public function setTemplate($template)
121
    {
122
        $this->template = $template;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @return array
129
     */
130
    public function getData()
131
    {
132
        return $this->data;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->data; (array) is incompatible with the return type declared by the interface Overtrue\EasySms\Contrac...ssageInterface::getData of type string.

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...
133
    }
134
135
    /**
136
     * @param array $data
137
     *
138
     * @return $this
139
     */
140
    public function setData(array $data)
141
    {
142
        $this->data = $data;
143
144
        return $this;
145
    }
146
147
    /**
148
     * @return array
149
     */
150
    public function getGateways()
151
    {
152
        return $this->gateways;
153
    }
154
155
    /**
156
     * @param array $gateways
157
     *
158
     * @return $this
159
     */
160
    public function setGateways(array $gateways)
161
    {
162
        $this->gateways = $gateways;
163
164
        return $this;
165
    }
166
167
    /**
168
     * @param $property
169
     *
170
     * @return string
171
     */
172
    public function __get($property)
173
    {
174
        if (property_exists($this, $property)) {
175
            return $this->$property;
176
        }
177
    }
178
}
179