Issues (37)

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/Comment/CommentModel.php (4 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 Mafd16\Comment;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
use \Anax\DI\InjectionAwareInterface;
8
use \Anax\Di\InjectionAwareTrait;
9
use \Mafd16\Comment\Comments;
10
11
/**
12
 * Comment system.
13
 */
14
class CommentModel implements
15
    ConfigureInterface,
16
    InjectionAwareInterface
17
{
18
    use ConfigureTrait,
19
        InjectionAwareTrait;
20
21
    /**
22
     * @var array $session inject a reference to the session.
23
     */
24
    //private $session;
25
26
27
28
    /**
29
     * @var string $key to use when storing in session.
30
     */
31
    const KEY = "commentsystem";
32
33
34
35
    /**
36
     * Inject dependencies.
37
     *
38
     * @param array $dependency key/value array with dependencies.
39
     *
40
     * @return self
41
     */
42
    //public function inject($dependency)
43
    //{
44
    //    $this->session = $dependency;
45
    //    return $this;
46
    //}
47
48
49
50
51
52
    /**
53
     * Get ALL comments from session
54
     *
55
     * @param string $key for data subset.
0 ignored issues
show
There is no parameter named $key. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
56
     *
57
     * @return object with the dataset
58
     */
59 5
    public function getComments()
60
    {
61
        // Using db as storage:
62
        // Get users from db
63 5
        $com = new Comments();
64 5
        $com->setDb($this->di->get("db"));
65 5
        $comments = $com->findAll();
66
67 5
        return $comments;
68
    }
69
70
71
    /**
72
     * Get ONE comment from session
73
     *
74
     * @param string $key for dataset.
0 ignored issues
show
There is no parameter named $key. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
75
     * @param int    $id for comment.
76
     *
77
     * @return array with the comment, name, email, id, or null if not exists
78
     */
79 5
    public function getComment($id)
80
    {
81
        // Using db
82 5
        $comments = $this->getComments();
83
        // Get comment with id $id
84 5
        $comment = null;
85 5
        foreach ($comments as $val) {
86 5
            if ($id == $val->id) {
87 5
                $comment = $val;
88 5
                break;
89
            }
90 5
        }
91 5
        return $comment;
92
    }
93
94
95
    /**
96
     * Add a comment to a dataset.
97
     *
98
     * @param array     $post   variables from posted comment
99
     *                          (article, name, email, comment)
100
     *
101
     * @return void
102
     */
103 5
    public function addComment($post)
104
    {
105
        // Connect to db
106 5
        $com = new Comments();
107 5
        $com->setDb($this->di->get("db"));
108
109 5
        $com->UserId = $post["id"];
110 5
        $com->UserName = $post["name"];
111 5
        $com->UserEmail = $post["email"];
112 5
        $com->comment = $post["comment"];
113
114 5
        $com->save();
115 5
    }
116
117
118
    /**
119
     * Update old comment with new comment
120
     *
121
     * @param int       $id         id for comment
122
     * @param array     $comment    the comment-array (name, email, comment, id)
123
     *
124
     * @return void
125
     */
126 2 View Code Duplication
    public function updateComment($id, $comment)
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...
127
    {
128
        // Connect to db
129 2
        $com = new Comments();
130 2
        $com->setDb($this->di->get("db"));
131
        // Get comment
132 2
        $com->find("id", $id);
133
        // Update comment
134 2
        $com->comment = $comment["comment"];
135
        // Save
136 2
        $com->save();
137 2
    }
138
139
140
    /**
141
     * Delete comment with key and id
142
     *
143
     * @param int    $id            to delete
144
     *
145
     * @return void
146
     */
147 1 View Code Duplication
    public function deleteComment($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...
148
    {
149
        // Set default timezone
150 1
        date_default_timezone_set('Europe/Stockholm');
151
        // Connect to db
152 1
        $com = new Comments();
153 1
        $com->setDb($this->di->get("db"));
154
        // Get comment
155 1
        $com->find("id", $id);
156
        // Delete (Update) comment
157 1
        $com->deleted = date("Y-m-d H:i:s");
158
        // Save
159 1
        $com->save();
160 1
    }
161
}
162