Issues (8)

Security Analysis    no request data  

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/Entity/Entry.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
namespace Del\Expenses\Entity;
4
5
use DateTime;
6
use Del\Expenses\Value\Category;
7
use LogicException;
8
9
/**
10
 * @Entity(repositoryClass="Del\Expenses\Repository\EntryRepository")
11
 * @InheritanceType("SINGLE_TABLE")
12
 * @DiscriminatorColumn(name="type", type="string")
13
 * @DiscriminatorMap({"IN" = "Del\Expenses\Entity\Income", "OUT" = "Del\Expenses\Entity\Expenditure"})
14
 */
15
abstract class Entry implements EntryInterface
16
{
17
    const VAT_NONE = 0;
18
    const VAT_EXC = 1;
19
    const VAT_INC = 2;
20
21
    /**
22
     * @Id
23
     * @Column(type="integer")
24
     * @GeneratedValue
25
     */
26
    private $id;
27
28
    /**
29
     * @Column(type="integer")
30
     */
31
    private $userId;
32
33
    /**
34
     * @Column(type="datetime")
35
     * @var DateTime
36
     */
37
    private $date;
38
39
    /** @Column(type="decimal",precision=11,scale=2) */
40
    private $amount;
41
42
    /**
43
     * @Column(type="decimal",precision=11,scale=2)
44
     * @var float $vatRate
45
     */
46
    private $vatRate;
47
48
    /**
49
     * @Column(type="decimal",precision=11,scale=2)
50
     * @var float
51
     */
52
    private $vat;
53
54
    /**
55
     * @Column(type="decimal",precision=11,scale=2)
56
     * @var float
57
     */
58
    private $total;
59
60
    /** @Column(type="string",length=50,nullable=true) */
61
    private $category;
62
63
    /** @Column(type="string",length=50,nullable=true) */
64
    private $description;
65
66
    /** @Column(type="string",length=255,nullable=true) */
67
    private $note;
68
69
    /**
70
     * Entry constructor.
71
     * @param int $vatRate
72
     */
73 16
    public function __construct($vatRate = 0)
74
    {
75 16
        $this->vatRate = $vatRate;
0 ignored issues
show
Documentation Bug introduced by
The property $vatRate was declared of type double, but $vatRate is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
76 16
        $this->amount = 0;
77 16
        $this->vat = 0;
0 ignored issues
show
Documentation Bug introduced by
The property $vat was declared of type double, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
78 16
        $this->total = 0;
0 ignored issues
show
Documentation Bug introduced by
The property $total was declared of type double, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
79 16
    }
80
81
    /**
82
     * @return int
83
     */
84 5
    public function getId()
85
    {
86 5
        return $this->id;
87
    }
88
89
    /**
90
     * @param int $id
91
     * @return Entry
92
     */
93 4
    public function setId($id)
94
    {
95 4
        $this->id = (int) $id;
96 4
        return $this;
97
    }
98
99
    /**
100
     * @return mixed
101
     */
102 5
    public function getUserId()
103
    {
104 5
        return $this->userId;
105
    }
106
107
    /**
108
     * @param mixed $userId
109
     * @return Entry
110
     */
111 7
    public function setUserId($userId)
112
    {
113 7
        $this->userId = $userId;
114 7
        return $this;
115
    }
116
117
    /**
118
     * @return DateTime
119
     */
120 3
    public function getDate()
121
    {
122 3
        return $this->date;
123
    }
124
125
    /**
126
     * @param DateTime $date
127
     * @return Entry
128
     */
129 7
    public function setDate(DateTime $date)
130
    {
131 7
        $this->date = $date;
132 7
        return $this;
133
    }
134
135
    /**
136
     * @return float
137
     */
138 7
    public function getAmount()
139
    {
140 7
        return $this->amount;
141
    }
142
143
    /**
144
     * @param float $amount
145
     * @return Entry
146
     */
147 10
    public function setAmount($amount, $vatPaid = self::VAT_NONE)
148
    {
149 10
        if ($vatPaid != self::VAT_NONE && $this->vatRate == 0) {
150
151
            throw new LogicException('Set a VAT rate before setting the amount, if inc/ex VAT');
152
153 10
        } elseif ($vatPaid == self::VAT_INC) {
154
155 1
            $fraction = 100 / $this->vatRate;
156 1
            $fraction ++ ;
157 1
            $vatAmount = $amount / $fraction;
158 1
            $total = $amount;
159 1
            $amount = $amount - $vatAmount;
160
161 9
        } elseif ($vatPaid == self::VAT_EXC) {
162
163 3
            $vatAmount = ($amount / 100) * $this->vatRate;
164 3
            $total = $amount + $vatAmount;
165
166
        } else {
167
168 6
            $vatAmount = 0;
169 6
            $total = $amount;
170 6
            $this->vatRate = 0;
0 ignored issues
show
Documentation Bug introduced by
The property $vatRate was declared of type double, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
171
172
        }
173 10
        $this->amount = $amount;
174 10
        $this->vat = $vatAmount;
0 ignored issues
show
Documentation Bug introduced by
It seems like $vatAmount can also be of type integer. However, the property $vat is declared as type double. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
175 10
        $this->total = $total;
176 10
        return $this;
177
    }
178
179
    /**
180
     * @return Category
181
     */
182 3
    public function getCategory()
183
    {
184 3
        return new Category($this->category);
185
    }
186
187
    /**
188
     * @param Category $category
189
     * @return Entry
190
     */
191 7
    public function setCategory(Category $category)
192
    {
193 7
        $this->category = $category->getValue();
194 7
        return $this;
195
    }
196
197
    /**
198
     * @return string
199
     */
200 3
    public function getDescription()
201
    {
202 3
        return $this->description;
203
    }
204
205
    /**
206
     * @param string $description
207
     * @return Entry
208
     */
209 7
    public function setDescription($description)
210
    {
211 7
        $this->description = $description;
212 7
        return $this;
213
    }
214
215
    /**
216
     * @return string
217
     */
218 3
    public function getNote()
219
    {
220 3
        return $this->note;
221
    }
222
223
    /**
224
     * @param string $note
225
     * @return Entry
226
     */
227 7
    public function setNote($note)
228
    {
229 7
        $this->note = $note;
230 7
        return $this;
231
    }
232
233
    /**
234
     * @return float
235
     */
236 5
    public function getVatRate()
237
    {
238 5
        return $this->vatRate;
239
    }
240
241
    /**
242
     * @param float $vatRate
243
     * @return Entry
244
     */
245 6
    public function setVatRate($vatRate)
246
    {
247 6
        $this->vatRate = $vatRate;
248 6
        return $this;
249
    }
250
251
    /**
252
     * @return float
253
     */
254 6
    public function getVat()
255
    {
256 6
        return $this->vat;
257
    }
258
259
    /**
260
     * @return float
261
     */
262 6
    public function getTotal()
263
    {
264 6
        return $this->total;
265
    }
266
}