Issues (108)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Broadcast/MessageBuilder.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace EntWeChat\Broadcast;
4
5
use EntWeChat\Core\Exceptions\RuntimeException;
6
use EntWeChat\Message\Raw as RawMessage;
7
use EntWeChat\Message\Text;
8
use EntWeChat\Support\Arr;
9
10
/**
11
 * Class MessageBuilder.
12
 */
13
class MessageBuilder
14
{
15
    /**
16
     * Message target user or group.
17
     *
18
     * @var array
19
     */
20
    protected $to = [];
21
22
    /**
23
     * Message type.
24
     *
25
     * @var string
26
     */
27
    protected $msgType;
28
29
    /**
30
     * Agent id.
31
     *
32
     * @var mixed
33
     */
34
    protected $agentId;
35
36
    /**
37
     * Message.
38
     *
39
     * @var mixed
40
     */
41
    protected $message;
42
43
    /**
44
     * Safe message.
45
     *
46
     * @var mixed
47
     */
48
    protected $safe = 0;
49
50
    /**
51
     * Broadcast instance.
52
     *
53
     * @var \EntWeChat\Broadcast\Broadcast
54
     */
55
    protected $broadcast;
56
57
    /**
58
     * Message types.
59
     *
60
     * @var array
61
     */
62
    private $msgTypes = [
0 ignored issues
show
The property $msgTypes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
63
        Broadcast::MSG_TYPE_TEXT,
64
        Broadcast::MSG_TYPE_NEWS,
65
        Broadcast::MSG_TYPE_IMAGE,
66
        Broadcast::MSG_TYPE_VIDEO,
67
        Broadcast::MSG_TYPE_VOICE,
68
        Broadcast::MSG_TYPE_CARD,
69
        Broadcast::MSG_TYPE_FILE,
70
        Broadcast::MSG_TYPE_MPNEWS,
71
        Broadcast::MSG_TYPE_TEXTCARD,
72
    ];
73
74
    /**
75
     * MessageBuilder constructor.
76
     *
77
     * @param \EntWeChat\Broadcast\Broadcast $broadcast
78
     */
79
    public function __construct(Broadcast $broadcast)
80
    {
81
        $this->broadcast = $broadcast;
82
    }
83
84
    /**
85
     * Set message.
86
     *
87
     * @param string|array $message
88
     *
89
     * @return $this
90
     */
91 View Code Duplication
    public function message($message)
0 ignored issues
show
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...
92
    {
93
        if (is_string($message)) {
94
            $message = new Text(['content' => $message]);
95
        }
96
97
        $this->message = $message;
98
99
        return $this;
100
    }
101
102
    /**
103
     * Set agent to send message.
104
     *
105
     * @param $agentId
106
     *
107
     * @return $this
108
     */
109
    public function by($agentId)
110
    {
111
        $this->agentId = $agentId;
112
113
        return $this;
114
    }
115
116
    /**
117
     * Set target user or group.
118
     *
119
     * @param array $to
120
     *
121
     * @return $this
122
     */
123
    public function to(array $to)
124
    {
125
        $this->to = Arr::only($to, ['touser', 'toparty', 'totag']);
126
127
        return $this;
128
    }
129
130
    /**
131
     * Message target all.
132
     *
133
     * @return $this
134
     */
135
    public function toAll()
136
    {
137
        $this->to['touser'] = '@all';
138
139
        return $this;
140
    }
141
142
    /**
143
     * Message target user.
144
     *
145
     * @return $this
146
     */
147 View Code Duplication
    public function toUser()
0 ignored issues
show
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...
148
    {
149
        if (func_num_args() > 0) {
150
            $userIds = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();
151
152
            $this->to['touser'] = implode('|', $userIds);
153
        }
154
155
        return $this;
156
    }
157
158
    /**
159
     * Message target party.
160
     *
161
     * @return $this
162
     */
163 View Code Duplication
    public function toParty()
0 ignored issues
show
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...
164
    {
165
        if (func_num_args() > 0) {
166
            $partyIds = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();
167
168
            $this->to['toparty'] = implode('|', $partyIds);
169
        }
170
171
        return $this;
172
    }
173
174
    /**
175
     * Message target tag.
176
     *
177
     * @return $this
178
     */
179 View Code Duplication
    public function toTag()
0 ignored issues
show
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...
180
    {
181
        if (func_num_args() > 0) {
182
            $tagIds = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();
183
184
            $this->to['totag'] = implode('|', $tagIds);
185
        }
186
187
        return $this;
188
    }
189
190
    /**
191
     * Use safe message.
192
     *
193
     * @return $this
194
     */
195
    public function safe()
196
    {
197
        $this->safe = 1;
198
199
        return $this;
200
    }
201
202
    /**
203
     * Send the message.
204
     *
205
     * @throws RuntimeException
206
     *
207
     * @return bool
208
     */
209 View Code Duplication
    public function send()
0 ignored issues
show
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...
210
    {
211
        if (empty($this->message)) {
212
            throw new RuntimeException('No message to send.');
213
        }
214
215
        $transformer = new Transformer();
216
217
        if ($this->message instanceof RawMessage) {
218
            $message = $this->message->get('content');
219
        } else {
220
            $content = $transformer->transform($this->message);
221
222
            $message = array_merge($this->to, ['agentid' => $this->agentId], ['safe' => $this->safe], $content);
223
        }
224
225
        return $this->broadcast->send($message);
226
    }
227
228
    /**
229
     * Return property.
230
     *
231
     * @param string $property
232
     *
233
     * @return mixed
234
     */
235
    public function __get($property)
236
    {
237
        if (property_exists($this, $property)) {
238
            return $this->$property;
239
        }
240
    }
241
}
242