Issues (443)

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.

common/models/Option.php (3 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
 * @link http://www.writesdown.com/
4
 * @copyright Copyright (c) 2015 WritesDown
5
 * @license http://www.writesdown.com/license/
6
 */
7
8
namespace common\models;
9
10
use common\components\Json;
11
use Yii;
12
use yii\db\ActiveRecord;
13
14
/**
15
 * This is the model class for table "{{%option}}".
16
 *
17
 * @property integer $id
18
 * @property string $name
19
 * @property string $value
20
 * @property string $label
21
 * @property string $group
22
 *
23
 * @author Agiel K. Saputra <[email protected]>
24
 * @since 0.1.0
25
 */
26
class Option extends ActiveRecord
27
{
28
    /**
29
     * @inheritdoc
30
     */
31
    public static function tableName()
32
    {
33
        return '{{%option}}';
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39 View Code Duplication
    public function rules()
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...
40
    {
41
        return [
42
            [['name', 'value'], 'required'],
43
            ['value', 'string'],
44
            [['name', 'label', 'group'], 'string', 'max' => 64],
45
        ];
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function attributeLabels()
52
    {
53
        return [
54
            'id' => Yii::t('writesdown', 'ID'),
55
            'name' => Yii::t('writesdown', 'Name'),
56
            'value' => Yii::t('writesdown', 'Value'),
57
            'label' => Yii::t('writesdown', 'Label'),
58
            'group' => Yii::t('writesdown', 'Group'),
59
        ];
60
    }
61
62
    /**
63
     * Get option value.
64
     * The return value array|boolean|string depends on value.
65
     * If value is string then the return value is a string.
66
     * If value is array|object then return value is array.
67
     * If name not found in table then it will return false.
68
     *
69
     * @param string $name
70
     * @return string|array|boolean
71
     */
72 View Code Duplication
    public static function get($name)
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...
73
    {
74
        /* @var $model \common\models\Option */
75
        $model = static::findOne(['name' => $name]);
76
77
        if ($model) {
78
            if (Json::isJson($model->value)) {
79
                return Json::decode($model->value);
80
            }
81
82
            return $model->value;
83
        }
84
85
        return null;
86
    }
87
88
    /**
89
     * Add new option, required name and value.
90
     * If value is array or object, it will be converted to json with Json::encode.
91
     *
92
     * @param string $name
93
     * @param string $value
94
     * @param string|array $label
95
     * @param string $group
96
     * @return bool
97
     */
98
    public static function set($name, $value, $label = null, $group = null)
99
    {
100
        if (is_array($value) || is_object($value)) {
101
            $value = Json::encode($value);
102
        }
103
104
        if (static::get($name) !== null) {
105
            return static::up($name, $value);
106
        }
107
108
        $model = new Option([
109
            'name' => $name,
110
            'value' => $value,
111
            'label' => $label,
112
            'group' => $group,
113
        ]);
114
115
        return $model->save();
116
    }
117
118
    /**
119
     * Update option with name as key.
120
     *
121
     * @param string $name
122
     * @param string|array $value
123
     * @return bool
124
     */
125
    public static function up($name, $value)
126
    {
127
        /* @var $model \common\models\Option */
128
        $model = static::findOne(['name' => $name]);
129
130
        if (is_array($value) || is_object($value)) {
131
            $model->value = Json::encode($value);
132
        } else {
133
            $model->value = $value;
134
        }
135
136
        return $model->save();
137
    }
138
139
    /**
140
     * Get menu item to render in admin sidebar left.
141
     *
142
     * @param int $position
143
     * @return array
144
     */
145
    public static function getMenus($position = 30)
146
    {
147
        $items[$position] = ['label' => Yii::t('writesdown', 'Settings'), 'icon' => 'fa fa-cogs'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $items = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
148
        $items[$position]['items'] = static::getSubmenus();
149
150
        return $items;
151
    }
152
153
    /**
154
     * The option will be grouped into group to create new submenu item.
155
     *
156
     * @return array|null
157
     */
158
    protected static function getSubmenus()
159
    {
160
        /* @var $model \common\models\Option */
161
        $models = static::find()
162
            ->groupBy('group')
163
            ->andWhere(['<>', 'group', ''])
164
            ->orderBy(['id' => SORT_ASC])
165
            ->all();
166
        $items = null;
167
168
        foreach ($models as $model) {
169
            $items[] = [
170
                'icon' => 'fa fa-circle-o',
171
                'label' => Yii::t('writesdown', ucwords($model->group)),
172
                'url' => ['/setting/group/', 'id' => strtolower($model->group)],
173
                'visible' => Yii::$app->user->can('administrator'),
174
            ];
175
        }
176
177
        return $items;
178
    }
179
}
180