Issues (14)

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.

models/Comment.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
 * Comment.php
4
 * @author Revin Roman
5
 * @link https://rmrevin.ru
6
 */
7
8
namespace rmrevin\yii\module\Comments\models;
9
10
use rmrevin\yii\module\Comments;
11
use yii\behaviors\BlameableBehavior;
12
use yii\behaviors\TimestampBehavior;
13
14
/**
15
 * Class Comment
16
 * @package rmrevin\yii\module\Comments\models
17
 *
18
 * @property integer $id
19
 * @property string $entity
20
 * @property string $from
21
 * @property string $text
22
 * @property integer $deleted
23
 * @property integer $created_by
24
 * @property integer $updated_by
25
 * @property integer $created_at
26
 * @property integer $updated_at
27
 *
28
 * @property \yii\db\ActiveRecord $author
29
 * @property \yii\db\ActiveRecord $lastUpdateAuthor
30
 *
31
 * @method queries\CommentQuery hasMany(string $class, array $link) see BaseActiveRecord::hasMany() for more info
32
 * @method queries\CommentQuery hasOne(string $class, array $link) see BaseActiveRecord::hasOne() for more info
33
 */
34
class Comment extends \yii\db\ActiveRecord
35
{
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function behaviors()
41
    {
42
        return [
43
            'blameable' => BlameableBehavior::className(),
44
            'timestamp' => TimestampBehavior::className(),
45
        ];
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function rules()
52
    {
53
        return [
54
            [['text'], 'required'],
55
            [['from', 'text'], 'string'],
56
            [['created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
57
            [['deleted'], 'boolean'],
58
            [['deleted'], 'default', 'value' => self::NOT_DELETED],
59
        ];
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65
    public function attributeLabels()
66
    {
67
        return [
68
            'id' => \Yii::t('app', 'ID'),
69
            'entity' => \Yii::t('app', 'Entity'),
70
            'from' => \Yii::t('app', 'Comment author'),
71
            'text' => \Yii::t('app', 'Text'),
72
            'created_by' => \Yii::t('app', 'Created by'),
73
            'updated_by' => \Yii::t('app', 'Updated by'),
74
            'created_at' => \Yii::t('app', 'Created at'),
75
            'updated_at' => \Yii::t('app', 'Updated at'),
76
        ];
77
    }
78
79
    /**
80
     * @return bool
81
     */
82
    public function isEdited()
83
    {
84
        return $this->created_at !== $this->updated_at;
85
    }
86
87
    /**
88
     * @return bool
89
     */
90
    public function isDeleted()
91
    {
92
        return $this->deleted === self::DELETED;
93
    }
94
95
    /**
96
     * @return bool
97
     */
98
    public static function canCreate()
99
    {
100
        return Comments\Module::instance()->useRbac === true
101
            ? \Yii::$app->getUser()->can(Comments\Permission::CREATE)
0 ignored issues
show
The method getUser does only exist in yii\web\Application, but not in yii\console\Application.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
102
            : true;
103
    }
104
105
    /**
106
     * @return bool
107
     */
108 View Code Duplication
    public function canUpdate()
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...
109
    {
110
        $User = \Yii::$app->getUser();
0 ignored issues
show
The method getUser does only exist in yii\web\Application, but not in yii\console\Application.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
111
112
        return Comments\Module::instance()->useRbac === true
113
            ? (\Yii::$app->getUser()->can(Comments\Permission::UPDATE) || \Yii::$app->getUser()->can(Comments\Permission::UPDATE_OWN, ['Comment' => $this]))
114
            : ($User->isGuest ? false : ($this->created_by === $User->id));
115
    }
116
117
    /**
118
     * @return bool
119
     */
120 View Code Duplication
    public function canDelete()
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...
121
    {
122
        $User = \Yii::$app->getUser();
0 ignored issues
show
The method getUser does only exist in yii\web\Application, but not in yii\console\Application.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
123
124
        return Comments\Module::instance()->useRbac === true
125
            ? (\Yii::$app->getUser()->can(Comments\Permission::DELETE) || \Yii::$app->getUser()->can(Comments\Permission::DELETE_OWN, ['Comment' => $this]))
126
            : ($User->isGuest ? false : ($this->created_by === $User->id));
127
    }
128
129
    /**
130
     * @return queries\CommentQuery
131
     */
132
    public function getAuthor()
133
    {
134
        return $this->hasOne(Comments\Module::instance()->userIdentityClass, ['id' => 'created_by']);
135
    }
136
137
    /**
138
     * @return queries\CommentQuery
139
     */
140
    public function getLastUpdateAuthor()
141
    {
142
        return $this->hasOne(Comments\Module::instance()->userIdentityClass, ['id' => 'updated_by']);
143
    }
144
145
    /**
146
     * @return queries\CommentQuery
147
     */
148
    public static function find()
149
    {
150
        return \Yii::createObject(
151
            Comments\Module::instance()->model('commentQuery'),
152
            [get_called_class()]
153
        );
154
    }
155
156
    /**
157
     * @inheritdoc
158
     */
159
    public static function tableName()
160
    {
161
        return '{{%comment}}';
162
    }
163
164
    const NOT_DELETED = 0;
165
    const DELETED = 1;
166
}