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/Transformer.php (5 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\Message\AbstractMessage;
6
use EntWeChat\Message\News;
7
use EntWeChat\Message\Text;
8
9
/**
10
 * Class Transformer.
11
 */
12
class Transformer
13
{
14
    /**
15
     * transform message to XML.
16
     *
17
     * @param array|string|AbstractMessage $message
18
     *
19
     * @return array
20
     */
21 View Code Duplication
    public function transform($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...
22
    {
23
        if (is_array($message)) {
24
            $class = News::class;
25
        } else {
26
            if (is_string($message)) {
27
                $message = new Text(['content' => $message]);
28
            }
29
30
            $class = get_class($message);
31
        }
32
33
        $handle = 'transform'.substr($class, strlen('EntWeChat\Message\\'));
34
35
        return method_exists($this, $handle) ? $this->$handle($message) : [];
36
    }
37
38
    /**
39
     * Transform text message.
40
     *
41
     * @return array
42
     */
43
    public function transformText(AbstractMessage $message)
44
    {
45
        return [
46
            'msgtype' => 'text',
47
            'text'    => [
48
                'content' => $message->get('content'),
49
            ],
50
        ];
51
    }
52
53
    /**
54
     * Transform image message.
55
     *
56
     * @return array
57
     */
58
    public function transformImage(AbstractMessage $message)
59
    {
60
        return [
61
            'msgtype' => 'image',
62
            'image'   => [
63
                'media_id' => $message->get('media_id'),
64
            ],
65
        ];
66
    }
67
68
    /**
69
     * Transform music message.
70
     *
71
     * @return array
72
     */
73 View Code Duplication
    public function transformMusic(AbstractMessage $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...
74
    {
75
        return [
76
            'msgtype' => 'music',
77
            'music'   => [
78
                'title'          => $message->get('title'),
79
                'description'    => $message->get('description'),
80
                'musicurl'       => $message->get('url'),
81
                'hqmusicurl'     => $message->get('hq_url'),
82
                'thumb_media_id' => $message->get('thumb_media_id'),
83
            ],
84
        ];
85
    }
86
87
    /**
88
     * Transform video message.
89
     *
90
     * @return array
91
     */
92 View Code Duplication
    public function transformVideo(AbstractMessage $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...
93
    {
94
        return [
95
            'msgtype' => 'video',
96
            'video'   => [
97
                'title'          => $message->get('title'),
98
                'media_id'       => $message->get('media_id'),
99
                'description'    => $message->get('description'),
100
                'thumb_media_id' => $message->get('thumb_media_id'),
101
            ],
102
        ];
103
    }
104
105
    /**
106
     * Transform voice message.
107
     *
108
     * @return array
109
     */
110
    public function transformVoice(AbstractMessage $message)
111
    {
112
        return [
113
            'msgtype' => 'voice',
114
            'voice'   => [
115
                'media_id' => $message->get('media_id'),
116
            ],
117
        ];
118
    }
119
120
    /**
121
     * Transform file message.
122
     *
123
     * @return array
124
     */
125
    public function transformFile(AbstractMessage $message)
126
    {
127
        return [
128
            'msgtype' => 'file',
129
            'file'    => [
130
                'media_id' => $message->get('media_id'),
131
            ],
132
        ];
133
    }
134
135
    /**
136
     * Transform articles message.
137
     *
138
     * @return array
139
     */
140 View Code Duplication
    public function transformNews($news)
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...
141
    {
142
        $articles = [];
143
144
        if (!is_array($news)) {
145
            $news = [$news];
146
        }
147
148
        foreach ($news as $item) {
149
            $articles[] = [
150
                'title'       => $item->get('title'),
151
                'description' => $item->get('description'),
152
                'url'         => $item->get('url'),
153
                'picurl'      => $item->get('pic_url'),
154
                'btntxt'      => $item->get('btntxt'),
155
            ];
156
        }
157
158
        return ['msgtype' => 'news', 'news' => ['articles' => $articles]];
159
    }
160
161
    /**
162
     * Transform articles message.
163
     *
164
     * @return array
165
     */
166
    public function transformMpNews($news)
167
    {
168
        $articles = [];
169
170
        if (!is_array($news)) {
171
            $news = [$news];
172
        }
173
174
        foreach ($news as $item) {
175
            $articles[] = [
176
                'title'              => $item->get('title'),
177
                'thumb_media_id'     => $item->get('thumb_media_id'),
178
                'author'             => $item->get('author'),
179
                'content_source_url' => $item->get('content_source_url'),
180
                'content'            => $item->get('content'),
181
                'digest'             => $item->get('digest'),
182
                'show_cover_pic'     => $item->get('show_cover_pic'),
183
            ];
184
        }
185
186
        return ['msgtype' => 'mpnews', 'news' => ['articles' => $articles]];
187
    }
188
189
    /**
190
     * Transform material message.
191
     *
192
     * @return array
193
     */
194 View Code Duplication
    public function transformMaterial(AbstractMessage $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...
195
    {
196
        $type = $message->getType();
197
198
        return [
199
            'msgtype' => $type,
200
            $type     => [
201
                'media_id' => $message->get('media_id'),
202
            ],
203
        ];
204
    }
205
206
    /**
207
     * Transform textcard message.
208
     *
209
     * @return array
210
     */
211
    public function transformTextCard(AbstractMessage $message)
212
    {
213
        return [
214
            'msgtype'  => 'textcard',
215
            'textcard' => [
216
                'title'       => $message->get('title'),
217
                'description' => $message->get('description'),
218
                'url'         => $message->get('url'),
219
                'btntxt'      => $message->get('btntxt'),
220
            ],
221
        ];
222
    }
223
224
    /**
225
     * Transform card message.
226
     *
227
     * @param $message
228
     *
229
     * @return array
230
     */
231
    public function transformCard($message)
232
    {
233
        return [
234
            'wxcard'  => [
235
                'card_id' => $message,
236
            ],
237
            'msgtype' => 'wxcard',
238
        ];
239
    }
240
}
241