Issues (70)

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/AppBundle/Entity/Survey/Survey.php (2 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 AppBundle\Entity\Survey;
4
5
use AppBundle\Entity\User;
6
use Doctrine\ORM\Mapping as ORM;
7
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Symfony\Component\Validator\Constraints as Assert;
10
11
/**
12
 * Survey.
13
 *
14
 * @ORM\Entity(repositoryClass="AppBundle\Repository\SurveyRepository")
15
 */
16
class Survey
17
{
18
    use ORMBehaviors\Timestampable\Timestampable;
19
20
    /**
21
     * @var int
22
     *
23
     * @ORM\Column(type="integer")
24
     * @ORM\Id
25
     * @ORM\GeneratedValue(strategy="AUTO")
26
     */
27
    private $id;
28
29
    /**
30
     * @var SurveyType
31
     * @Assert\Type("object")
32
     * @Assert\Valid
33
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Survey\SurveyType", inversedBy="surveys")
34
     * @ORM\JoinColumn(onDelete="SET NULL")
35
     */
36
    private $type;
37
38
    /**
39
     * @var string
40
     * @Assert\NotBlank()
41
     * @Assert\Type("string")
42
     * @ORM\Column(type="string")
43
     */
44
    private $status;
45
46
    /**
47
     * @var bool
48
     * @Assert\Type("bool")
49
     * @ORM\Column(type="boolean")
50
     */
51
    private $reviewed;
52
53
    /**
54
     * @var User
55
     * @Assert\Type("object")
56
     * @Assert\Valid
57
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="surveys")
58
     * @ORM\JoinColumn(onDelete="CASCADE")
59
     */
60
    private $user;
61
62
    /**
63
     * @var ArrayCollection[SurveyAnswer]
64
     * @ORM\OneToMany(targetEntity="SurveyAnswer", mappedBy="survey", cascade={"persist", "remove"})
65
     */
66
    private $answers;
67
68 1
    public function __construct()
69
    {
70 1
        $this->answers = new ArrayCollection();
71 1
        $this->status = 'current';
72 1
        $this->reviewed = false;
73 1
    }
74
75
    /**
76
     * Get id.
77
     *
78
     * @return int
79
     */
80 2
    public function getId()
81
    {
82 2
        return $this->id;
83
    }
84
85
    /**
86
     * Set type.
87
     *
88
     * @param SurveyType $type
89
     *
90
     * @return Survey
91
     */
92 1
    public function setType(SurveyType $type)
93
    {
94 1
        $this->type = $type;
95
96 1
        return $this;
97
    }
98
99
    /**
100
     * Get type.
101
     *
102
     * @return SurveyType
103
     */
104 6
    public function getType()
105
    {
106 6
        return $this->type;
107
    }
108
109
    /**
110
     * Set status.
111
     *
112
     * @param string $status
113
     *
114
     * @return Survey
115
     */
116 1
    public function setStatus($status)
117
    {
118 1
        $this->status = $status;
119
120 1
        return $this;
121
    }
122
123
    /**
124
     * Get status.
125
     *
126
     * @return string
127
     */
128 3
    public function getStatus()
129
    {
130 3
        return $this->status;
131
    }
132
133
    /**
134
     * Set review.
135
     *
136
     * @param bool $review
137
     *
138
     * @return Survey
139
     */
140 1
    public function setReviewed($review)
141
    {
142 1
        $this->reviewed = $review;
143
144 1
        return $this;
145
    }
146
147
    /**
148
     * Get review.
149
     *
150
     * @return bool
151
     */
152 1
    public function isReviewed()
153
    {
154 1
        return $this->reviewed;
155
    }
156
157
    /**
158
     * Set user.
159
     *
160
     * @param User $user
161
     *
162
     * @return Survey
163
     */
164 1
    public function setUser(User $user)
165
    {
166 1
        $this->user = $user;
167
168 1
        return $this;
169
    }
170
171
    /**
172
     * Get user.
173
     *
174
     * @return User
175
     */
176 4
    public function getUser()
177
    {
178 4
        return $this->user;
179
    }
180
181
    /**
182
     * @param SurveyAnswer $answer
183
     *
184
     * @return Survey
185
     */
186
    public function addSurveyAnswer(SurveyAnswer $answer)
187
    {
188
        if (!$this->answers->contains($answer)) {
189
            $this->answers->add($answer);
190
            $answer->setSurvey($this);
191
        }
192
193
        return $this;
194
    }
195
196
    /**
197
     * Get answers.
198
     *
199
     * @return ArrayCollection
200
     */
201
    public function getAnswers()
202
    {
203
        return $this->answers;
204
    }
205
206
    /**
207
     * Get questions.
208
     *
209
     * @return array
210
     */
211 1
    public function getQuestions()
212
    {
213 1
        $sections = $this->getType()->getSections();
214 1
        foreach ($sections as $section) {
215 1
            foreach ($section->getQuestions() as $quest) {
216 1
                $questions[] = $quest;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$questions was never initialized. Although not strictly required by PHP, it is generally a good practice to add $questions = 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...
217
            }
218
        }
219
220 1
        return $questions;
0 ignored issues
show
The variable $questions does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
221
    }
222
223
    /**
224
     * Add answer.
225
     *
226
     * @param SurveyAnswer $answer
227
     *
228
     * @return Survey
229
     */
230
    public function addAnswer(SurveyAnswer $answer)
231
    {
232
        $this->answers[] = $answer;
233
234
        return $this;
235
    }
236
237
    /**
238
     * Remove answer.
239
     *
240
     * @param SurveyAnswer $answer
241
     */
242
    public function removeAnswer(SurveyAnswer $answer)
243
    {
244
        $this->answers->removeElement($answer);
245
    }
246
}
247