Issues (18)

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/IncomeExpense.php (14 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
4
/**
5
 * Author: Emmanuel Paul Mnzava
6
 * Twitter: @epmnzava
7
 * Github:https://github.com/dbrax/income-expense
8
 * Email: [email protected]
9
 *
10
 */
11
12
namespace Epmnzava\IncomeExpense;
13
14
use Epmnzava\IncomeExpense\Models\Expense;
15
use Epmnzava\IncomeExpense\Models\ExpenseCategory;
16
use Epmnzava\IncomeExpense\Models\Income;
17
use Epmnzava\IncomeExpense\Models\IncomeCategory;
18
use Epmnzava\IncomeExpense\Models\Ledger;
19
use Illuminate\Support\Str;
20
21
class IncomeExpense extends AccountingData
22
{
23
24
25
    /**
26
     * @param int $categoryid
27
     * @param string $income_title
28
     * @param int $amount
29
     * @param string $notes
30
     * @param string $transaction_id
31
     * @return Income
32
     *
33
     * function to add an income and ledger at the same time
34
     */
35 View Code Duplication
    public function add_income(int $categoryid, string $income_title, int $amount, string $notes = "", $transaction_id = "0"): Income
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...
36
    {
37
38
        $income = $this->newIncome($categoryid, $income_title, $amount, $notes, $transaction_id);
0 ignored issues
show
The call to IncomeExpense::newIncome() has too many arguments starting with $transaction_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
39
40
        if ($transaction_id == 0)
41
            $transaction_id = $this->set_transaction_id($income);
42
43
44
        $ledger = $this->add_transaction_on_ledger($income, "INC", $transaction_id);
0 ignored issues
show
$ledger is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
45
46
        return $income;
47
    }
48
49
    /**
50
     * @param int $categoryid
51
     * @param string $income_title
52
     * @param int $amount
0 ignored issues
show
There is no parameter named $income_title. 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...
53
     * @param string $notes
54
     * @param string $transaction_id
55
     * @return Expense
56
     *
57
     * function to add expense and to a ledger at the sametime
58
     */
59
60 View Code Duplication
    public function add_expense(int $categoryid, string $expense_title, int $amount, string $notes = "", $transaction_id = "0"): Expense
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...
61
    {
62
63
        $expense = $this->newExpense($categoryid, $expense_title, $amount, $notes, $transaction_id);
0 ignored issues
show
The call to IncomeExpense::newExpense() has too many arguments starting with $transaction_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
64
65
        if ($transaction_id == 0)
66
            $transaction_id = $this->set_transaction_id($expense);
67
68
69
        $ledger = $this->add_transaction_on_ledger($expense, "EXP", $transaction_id);
0 ignored issues
show
$ledger is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
71
        return $expense;
72
    }
73
74
75
    /**
76
     * @param $income
77
     * @return string
78
     * @throws \Exception
79
     *
80
     * function that sets a transaction id
81
     */
82
83
    public function set_transaction_id($income)
0 ignored issues
show
The parameter $income is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84
    {
85
        $prefix = config('income-expense.transaction_id_prefix');
86
        $length = config('income-expense.transaction_id_length');
87
88
        $keyspace = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
89
90
        $str = '';
91
92
        $max = mb_strlen($keyspace, '8bit') - 1;
93
94
        for ($i = 0; $i < $length; ++$i) {
95
            $str .= $keyspace[random_int(0, $max)];
96
        }
97
98
        return $prefix . $str;
99
    }
100
101
    /**
102
     * @param int $categoryid
103
     * @param string $income_title
104
     * @param int $amount
105
     * @param string $notes
106
     * @return Income
107
     *
108
     * Unit function that adds income
109
     */
110
    private function newIncome(int $categoryid, string $income_title, int $amount, string $notes = ""): Income
111
    {
112
        return Income::create([
113
            "incomecategory" => $categoryid,
114
            "income_title" => $income_title,
115
            "amount" => $amount,
116
            "notes" => $notes,
117
            "date" => date('Y-m-d')
118
        ]);
119
    }
120
121
    /**
122
     * @param $transactionObj
123
     * @param $type
124
     * @param $transaction_id
125
     * @return Ledger
126
     *
127
     * unit function that adds a ledger transaction
128
     */
129
    public function add_transaction_on_ledger($transactionObj, $type, $transaction_id): Ledger
130
    {
131
132
        $ledger = new Ledger;
133
        $ledger->transaction_id = $transaction_id;
134
        $ledger->transaction_type = $type;
135
        if($type=="INC")
136
        $ledger->transaction_type_category = $transactionObj->incomecategory;
137
        else
138
        $ledger->transaction_type_category = $transactionObj->expense_category;
139
140
        $ledger->amount = $transactionObj->amount;
141
        $ledger->save();
142
        return $ledger;
143
    }
144
145
    /**
146
     * @param int $categoryid
147
     * @param string $expense_title
148
     * @param int $amount
149
     * @param string $notes
150
     * @return Expense
151
     *
152
     * A unit function that adds new expense
153
     */
154
155
    private function newExpense(int $categoryid, string $expense_title, int  $amount, string $notes = ""): Expense
156
    {
157
        return Expense::create([
158
            "expense_category" => $categoryid,
159
            "expense_title" => $expense_title,
160
            "amount" => $amount,
161
            "notes" => $notes,
162
            "date" => date('Y-m-d')
163
        ]);
164
    }
165
166
167
    /**
168
     * @param $categoryname
169
     * @param $description
170
     * @return ExpenseCategory
171
     *
172
     * A unit function that adds expense category
173
     */
174 View Code Duplication
    public function addExpenseCategory($categoryname, $description): ExpenseCategory
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...
175
    {
176
        return  ExpenseCategory::create([
177
            "category" => $categoryname,
178
            "description" => $description,
179
            "slug"=>Str::slug($categoryname, '-'),
180
            "date" => date('Y-m-d')
181
        ]);
182
    }
183
184
    /**
185
     * @param $categoryname
186
     * @param $description
187
     * @return IncomeCategory
188
     *
189
     * A unit function that adds income category
190
     */
191
192
193 View Code Duplication
    public function addIncomeCategory($categoryname, $description): IncomeCategory
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...
194
    {
195
196
        return  IncomeCategory::create([
197
            "category" => $categoryname,
198
            "description" => $description,
199
            "slug"=>Str::slug($categoryname, '-'),
200
            "date" => date('Y-m-d')
201
        ]);
202
    }
203
204
    /**
205
     * @param $expensecategoryid
206
     * @return Expense
207
     *
208
     * Function that return a specific expense category instance by passing in an expense category id
209
     */
210
    public function getExpenseCategoryById($expensecategoryid) : ExpenseCategory
211
    {
212
        return ExpenseCategory::find($expensecategoryid);
213
    }
214
215
216
    /**
217
     * @param $incomecategoryid
218
     * @return Income
219
     *
220
     * Function that returns a particular IncomeCatgory by passing in an incomecategoryid
221
     */
222
    public function getIncomeCategoryById($incomecategoryid) : IncomeCategory
223
    {
224
        return IncomeCategory::find($incomecategoryid);
225
    }
226
227
    public function deleteExpenseCategory($expensecategoryid)
0 ignored issues
show
The parameter $expensecategoryid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
228
    {
229
    }
230
231
232
    public function deleteIncomeCategory($incomecategoryid)
0 ignored issues
show
The parameter $incomecategoryid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
233
    {
234
    }
235
236
237
    public function updateExpenseCategory($expensecategoryid)
0 ignored issues
show
The parameter $expensecategoryid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
238
    {
239
    }
240
241
242
    public function updateIncomeCategory($incomecategoryid)
0 ignored issues
show
The parameter $incomecategoryid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
243
    {
244
    }
245
}
246