This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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
|
|||
36 | { |
||
37 | |||
38 | $income = $this->newIncome($categoryid, $income_title, $amount, $notes, $transaction_id); |
||
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); |
||
45 | |||
46 | return $income; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param int $categoryid |
||
51 | * @param string $income_title |
||
52 | * @param int $amount |
||
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. ![]() |
|||
61 | { |
||
62 | |||
63 | $expense = $this->newExpense($categoryid, $expense_title, $amount, $notes, $transaction_id); |
||
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); |
||
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) |
||
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. ![]() |
|||
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. ![]() |
|||
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) |
||
228 | { |
||
229 | } |
||
230 | |||
231 | |||
232 | public function deleteIncomeCategory($incomecategoryid) |
||
233 | { |
||
234 | } |
||
235 | |||
236 | |||
237 | public function updateExpenseCategory($expensecategoryid) |
||
238 | { |
||
239 | } |
||
240 | |||
241 | |||
242 | public function updateIncomeCategory($incomecategoryid) |
||
243 | { |
||
244 | } |
||
245 | } |
||
246 |
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.