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/Service/ExpensesService.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 Del\Expenses\Service;
4
5
use DateTime;
6
use Del\Expenses\Criteria\EntryCriteria;
7
use Del\Expenses\Entity\EntryInterface;
8
use Del\Expenses\Entity\Expenditure;
9
use Del\Expenses\Entity\Income;
10
use Del\Expenses\Repository\EntryRepository;
11
use Del\Expenses\Value\Category;
12
13
14
class ExpensesService
15
{
16
    /** @var float $vatRate */
17
    private $vatRate;
18
19
    /** @var EntryRepository $repository */
20
    protected $repository;
21
22 6
    public function __construct(EntryRepository $repository, $vatRate = 20)
23
    {
24 6
        $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...
25 6
        $this->repository = $repository;
26 6
    }
27
28
    /**
29
     * @return EntryRepository
30
     */
31 3
    private function getRepository()
32
    {
33 3
        return $this->repository;
34
    }
35
36
    /**
37
     * @param array $data
38
     * @param EntryInterface $entry
39
     * @return EntryInterface
40
     */
41 6
    private function setFromArray(array $data, EntryInterface $entry)
42
    {
43 6
        if(!$data['date'] instanceof DateTime) {
44 2
            $data['date'] = new DateTime($data['date']);
45
        }
46 6
        isset($data['id']) ? $entry->setId($data['id']) : null;
0 ignored issues
show
$data['id'] is of type object<DateTime>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47 6
        $entry->setUserId($data['userId'])
48 6
            ->setCategory(new Category($data['category']))
49 6
            ->setVatRate($data['vatRate'])
50 6
            ->setAmount($data['amount'], $data['vat'])
51 6
            ->setDate($data['date'])
52 6
            ->setDescription($data['description'])
53 6
            ->setNote($data['note']);
54 6
        return $entry;
55
    }
56
57
    /**
58
     * @return Expenditure
59
     */
60 4
    public function createExpenditureFromArray(array $data)
61
    {
62 4
        $expenditure = new Expenditure();
63
        /** @var Expenditure $expenditure */
64 4
        $expenditure = $this->setFromArray($data, $expenditure);
65 4
        return $expenditure;
66
    }
67
68
    /**
69
     * @return Income
70
     */
71 3
    public function createIncomeFromArray(array $data)
72
    {
73 3
        $income = new Income();
74
        /** @var Income $income */
75 3
        $income = $this->setFromArray($data, $income);
76 3
        return $income;
77
    }
78
79
    /**
80
     * Pass an Income, Expenditure, or Expense Claim
81
     * @return array
82
     */
83 1
    public function toArray(EntryInterface $entry)
84
    {
85
        return [
86 1
            'id' => $entry->getId(),
87 1
            'userId' => $entry->getUserId(),
88 1
            'date' => $entry->getDate(),
89 1
            'amount' => $entry->getAmount(),
90 1
            'vatRate' => $entry->getVatRate(),
91 1
            'vat' => $entry->getVat(),
92 1
            'total' => $entry->getTotal(),
93 1
            'description' => $entry->getDescription(),
94 1
            'category' => $entry->getCategory()->getValue(),
95 1
            'note' => $entry->getNote(),
96
        ];
97
    }
98
99
    /**
100
     * @param Income $income
101
     * @return Income
102
     */
103 2
    public function saveIncome(Income $income)
104
    {
105 2
        return $this->getRepository()->save($income);
106
    }
107
108
    /**
109
     * @param Income $income
110
     */
111 2
    public function deleteIncome(Income $income)
112
    {
113 2
        $this->deleteEntry($income);
114 2
    }
115
116
    /**
117
     * @param $id
118
     * @return Income
119
     */
120 1
    public function findIncomeById($id)
121
    {
122 1
        $criteria = new EntryCriteria();
123 1
        $criteria->setId($id);
124 1
        return $this->getRepository()->findOneByCriteria($criteria);
125
    }
126
127
    /**
128
     * @param Expenditure $expenditure
129
     * @return Expenditure
130
     */
131 2
    public function saveExpenditure(Expenditure $expenditure)
132
    {
133 2
        return $this->getRepository()->save($expenditure);
134
    }
135
136
    /**
137
     * @param Expenditure $expenditure
138
     */
139 2
    public function deleteExpenditure(Expenditure $expenditure)
140
    {
141 2
        $this->deleteEntry($expenditure);
142 2
    }
143
144
    /**
145
     * @param $id
146
     * @return Expenditure
147
     */
148 1
    public function findExpenditureById($id)
149
    {
150 1
        $criteria = new EntryCriteria();
151 1
        $criteria->setId($id);
152 1
        return $this->getRepository()->findOneByCriteria($criteria);
153
    }
154
155
    /**
156
     * @param EntryCriteria $criteria
157
     * @return array
158
     */
159 1
    public function findByCriteria(EntryCriteria $criteria)
160
    {
161 1
        return $this->getRepository()->findByCriteria($criteria);
162
    }
163
164
    /**
165
     * @param EntryInterface $entry
166
     */
167 3
    public function deleteEntry(EntryInterface $entry)
168
    {
169 3
        $this->getRepository()->delete($entry);
170 3
    }
171
172
    /**
173
     * @return float
174
     */
175
    public function getVatRate()
176
    {
177
        return $this->vatRate;
178
    }
179
180
    /**
181
     * @param float $vatRate
182
     * @return ExpensesService
183
     */
184
    public function setVatRate($vatRate)
185
    {
186
        $this->vatRate = $vatRate;
187
        return $this;
188
    }
189
}