Issues (123)

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.

app/Http/ApiControllers/RepliesController.php (8 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 PHPHub\Http\ApiControllers;
4
5
use Dingo\Api\Exception\StoreResourceFailedException;
6
use PHPHub\Repositories\ReplyRepositoryInterface;
7
use PHPHub\Transformers\ReplyTransformer;
8
use PHPHub\User;
9
use Illuminate\Http\Request;
10
use Prettus\Validator\Exceptions\ValidatorException;
11
12
class RepliesController extends Controller
13
{
14
    /**
15
     * @var ReplyRepositoryInterface
16
     */
17
    private $replies;
18
19
    /**
20
     * TopicController constructor.
21
     *
22
     * @param ReplyRepositoryInterface $repository
23
     */
24
    public function __construct(ReplyRepositoryInterface $repository)
25
    {
26
        $this->replies = $repository;
27
    }
28
29
    /**
30
     * 获取指定帖子的回复.
31
     *
32
     * @param $topic_id
33
     *
34
     * @return \Illuminate\Http\Response
35
     */
36 View Code Duplication
    public function indexByTopicId($topic_id)
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...
37
    {
38
        $this->replies->addAvailableInclude('user', ['name', 'avatar']);
39
40
        $data = $this->replies
41
            ->byTopicId($topic_id)
42
            ->autoWith()
43
            ->autoWithRootColumns(['id', 'vote_count', 'created_at'])
44
            ->paginate(per_page());
45
46
        return $this->response()->paginator($data, new ReplyTransformer());
47
    }
48
49
    /**
50
     * 获取指定用户的回复.
51
     *
52
     * @param $user_id
53
     *
54
     * @return \Dingo\Api\Http\Response
55
     */
56 View Code Duplication
    public function indexByUserId($user_id)
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...
57
    {
58
        $this->replies->addAvailableInclude('user', ['name', 'avatar']);
59
60
        $data = $this->replies
61
            ->byUserId($user_id)
62
            ->autoWith()
63
            ->autoWithRootColumns(['id', 'vote_count'])
64
            ->paginate(per_page());
65
66
        return $this->response()->paginator($data, new ReplyTransformer());
67
    }
68
69
    /**
70
     * 发布一条新回复.
71
     *
72
     * @param \Illuminate\Http\Request $request
73
     *
74
     * @return \Illuminate\Http\Response
75
     */
76 View Code Duplication
    public function store(Request $request)
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...
77
    {
78
        try {
79
            $reply = $this->replies->store($request->all());
80
81
            return $this->response()->item($reply, new ReplyTransformer());
82
        } catch (ValidatorException $e) {
83
            throw new StoreResourceFailedException('Could not create new topic.', $e->getMessageBag()->all());
84
        }
85
    }
86
87
    /**
88
     * 更新回复.
89
     *
90
     * @param \Illuminate\Http\Request $request
91
     * @param int                      $id
92
     *
93
     * @return \Illuminate\Http\Response
94
     */
95
    public function update(Request $request, $id)
0 ignored issues
show
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
        //
98
    }
99
100
    /**
101
     * 删除一条回复.
102
     *
103
     * @param int $id
104
     *
105
     * @return \Illuminate\Http\Response
106
     */
107
    public function destroy($id)
0 ignored issues
show
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
108
    {
109
        //
110
    }
111
112
    /**
113
     * 指定帖子下评论列表的 Web View.
114
     *
115
     * @param $topic_id
116
     *
117
     * @return \Illuminate\View\View
118
     */
119
    public function indexWebViewByTopic($topic_id)
120
    {
121
        $replies = $this->replies
122
            ->byTopicId($topic_id)
123
            ->withOnly('user', ['id', 'name', 'avatar'])
124
            ->all(['id', 'body', 'created_at', 'user_id']);
125
126
        // 楼层计数
127
        $count = 1;
128
129
        return view('api_web_views.replies_list', compact('replies', 'count'));
0 ignored issues
show
Bug Compatibility introduced by
The expression view('api_web_views.repl...t('replies', 'count')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 129 which is incompatible with the return type documented by PHPHub\Http\ApiControlle...er::indexWebViewByTopic of type Illuminate\View\View.
Loading history...
130
    }
131
132
    /**
133
     * 指定帖子下评论列表的 Web View.
134
     *
135
     * @param $user_id
136
     *
137
     * @return \Illuminate\View\View
138
     */
139
    public function indexWebViewByUser($user_id)
140
    {
141
        $replies = $this->replies
142
            ->byUserId($user_id)
143
            ->withOnly('topic.user', ['avatar'])
144
            ->all(['id', 'body', 'created_at', 'topic_id']);
145
146
        return view('api_web_views.users_replies_list', compact('replies', 'count'));
0 ignored issues
show
Bug Compatibility introduced by
The expression view('api_web_views.user...t('replies', 'count')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 146 which is incompatible with the return type documented by PHPHub\Http\ApiControlle...ler::indexWebViewByUser of type Illuminate\View\View.
Loading history...
147
    }
148
}
149