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.

backend/controllers/TermRelationshipController.php (11 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 backend\controllers;
9
10
use common\models\Term;
11
use common\models\TermRelationship;
12
use Yii;
13
use yii\filters\AccessControl;
14
use yii\filters\VerbFilter;
15
use yii\web\Controller;
16
use yii\web\NotFoundHttpException;
17
18
/**
19
 * TermRelationshipController implements the CRUD actions for TermRelationship model.
20
 *
21
 * @author Agiel K. Saputra <[email protected]>
22
 * @since 0.1.0
23
 */
24
class TermRelationshipController extends Controller
25
{
26
    /**
27
     * @inheritdoc
28
     */
29 View Code Duplication
    public function behaviors()
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...
30
    {
31
        return [
32
            'access' => [
33
                'class' => AccessControl::className(),
34
                'rules' => [
35
                    [
36
                        'actions' => [
37
                            'ajax-change-hierarchical',
38
                            'ajax-create-non-hierarchical',
39
                            'ajax-delete-non-hierarchical',
40
                        ],
41
                        'allow' => true,
42
                        'roles' => ['subscriber'],
43
                    ],
44
                ],
45
            ],
46
            'verbs' => [
47
                'class' => VerbFilter::className(),
48
                'actions' => [
49
                    'ajax-change-hierarchical' => ['post'],
50
                    'ajax-create-non-hierarchical' => ['post'],
51
                    'ajax-delete-non-hierarchical' => ['post'],
52
                ],
53
            ],
54
55
        ];
56
    }
57
58
    /**
59
     * If user change the value of checkbox when updating a post, this action will be triggered.
60
     * If the checkbox checked it will trigger addItem (create TermRelationship) while if unchecked will trigger
61
     * remItem (remove TermRelationship).
62
     *
63
     * @throws \Exception
64
     * @throws \yii\web\NotFoundHttpException
65
     */
66
    public function actionAjaxChangeHierarchical()
67
    {
68
        if (Yii::$app->request->post('action') === 'addItem') {
69
            $model = new TermRelationship();
70
            $model->load(Yii::$app->request->post());
71 View Code Duplication
            if ($model->save()) {
0 ignored issues
show
This code seems to be duplicated across 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...
72
                if ($term = $this->findTerm($model->term_id)) {
73
                    $term->updateAttributes(['count' => ++$term->count]);
0 ignored issues
show
The method updateAttributes cannot be called on $term (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
74
                }
75
            }
76
        } elseif (Yii::$app->request->post('action') === 'remItem'
77
            && $termRelationship = Yii::$app->request->post('TermRelationship')
78
        ) {
79
            $model = $this->findModel($termRelationship['post_id'], $termRelationship['term_id']);
80 View Code Duplication
            if ($model->delete()) {
0 ignored issues
show
The method delete cannot be called on $model (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
This code seems to be duplicated across 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...
81
                if ($term = $this->findTerm($model->term_id)) {
82
                    $term->updateAttributes(['count' => --$term->count]);
0 ignored issues
show
The method updateAttributes cannot be called on $term (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
83
                }
84
            }
85
        }
86
    }
87
88
    /**
89
     * Create new TermRelationship model through AJAX via Seletize box on 'create' and 'update post' page.
90
     */
91
    public function actionAjaxCreateNonHierarchical()
92
    {
93
        $model = new TermRelationship();
94
95 View Code Duplication
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
0 ignored issues
show
This code seems to be duplicated across 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...
96
            if ($term = $this->findTerm($model->term_id)) {
97
                $term->updateAttributes(['count' => ++$term->count]);
0 ignored issues
show
The method updateAttributes cannot be called on $term (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
98
            }
99
        }
100
    }
101
102
    /**
103
     * Delete TermRelationship for non-hierarchical Taxonomy
104
     * which is triggered when the user remove item in Selectize box.
105
     *
106
     * @throws \Exception
107
     * @throws \yii\web\NotFoundHttpException
108
     */
109
    public function actionAjaxDeleteNonHierarchical()
110
    {
111
        if ($termRelationship = Yii::$app->request->post('TermRelationship')) {
112
            $model = $this->findModel($termRelationship['post_id'], $termRelationship['term_id']);
113 View Code Duplication
            if ($model->delete()) {
0 ignored issues
show
The method delete cannot be called on $model (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
This code seems to be duplicated across 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...
114
                if ($term = $this->findTerm($model->term_id)) {
115
                    $term->updateAttributes(['count' => --$term->count]);
0 ignored issues
show
The method updateAttributes cannot be called on $term (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
116
                }
117
            }
118
        }
119
    }
120
121
    /**
122
     * Finds the TermRelationship model based on its primary key value.
123
     * If the model is not found, a 404 HTTP exception will be thrown.
124
     *
125
     * @param integer $post_id
126
     * @param integer $term_id
127
     * @return TermRelationship the loaded model
128
     * @throws NotFoundHttpException if the model cannot be found
129
     */
130
    protected function findModel($post_id, $term_id)
131
    {
132
        if (($model = TermRelationship::findOne(['post_id' => $post_id, 'term_id' => $term_id])) !== null) {
133
            return $model;
134
        }
135
136
        throw new NotFoundHttpException('The requested page does not exist.');
137
    }
138
139
    /**
140
     * Finds the Term model based on its primary key value.
141
     * If the model is not found, a 404 HTTP exception will be thrown.
142
     *
143
     * @param integer $id
144
     * @return Term|false the loaded model
145
     */
146
    protected function findTerm($id)
147
    {
148
        if ($model = Term::findOne($id)) {
149
            return $model;
150
        }
151
152
        return false;
153
    }
154
}
155