| Conditions | 4 |
| Total Lines | 59 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { Injectable } from '@nestjs/common'; |
||
| 10 | |||
| 11 | public create(elements: UserElementsView[]): Table { |
||
| 12 | const columns = [ |
||
| 13 | 'payroll-elements-user', |
||
| 14 | 'payroll-elements-contract', |
||
| 15 | 'payroll-elements-joiningDate', |
||
| 16 | 'payroll-elements-annualEarnings', |
||
| 17 | 'payroll-elements-monthlyEarnings', |
||
| 18 | 'payroll-elements-workingTime', |
||
| 19 | 'payroll-elements-transportFee', |
||
| 20 | 'payroll-elements-sustainableMobilityFee', |
||
| 21 | 'payroll-elements-mealTickets', |
||
| 22 | 'payroll-elements-healthInsurance', |
||
| 23 | 'payroll-elements-paidLeaves', |
||
| 24 | 'payroll-elements-unpaidLeaves', |
||
| 25 | 'payroll-elements-medicalLeaves', |
||
| 26 | 'payroll-elements-specialLeaves' |
||
| 27 | ]; |
||
| 28 | |||
| 29 | const rows = []; |
||
| 30 | |||
| 31 | for (const item of elements) { |
||
| 32 | const row = this.cells |
||
| 33 | .createBuilder() |
||
| 34 | .value(formatFullName(item)) |
||
| 35 | .trans('payroll-elements-contract-value', { |
||
| 36 | contract: item.contract, |
||
| 37 | executivePosition: item.isExecutivePosition ? 'yes' : 'no' |
||
| 38 | }) |
||
| 39 | .trans('common-date', { date: new Date(item.joiningDate) }) |
||
| 40 | .trans('common-money', { value: item.annualEarnings }) |
||
| 41 | .trans('common-money', { value: item.monthlyEarnings }) |
||
| 42 | .trans('users-workingTime-value', { |
||
| 43 | workingTime: item.workingTime |
||
| 44 | }) |
||
| 45 | .trans('common-money', { value: item.transportFee }) |
||
| 46 | .trans('common-money', { |
||
| 47 | value: item.sustainableMobilityFee |
||
| 48 | }) |
||
| 49 | .value(item.mealTickets) |
||
| 50 | .trans(item.healthInsurance ? 'common-yes' : 'common-no') |
||
| 51 | .template('pages/payroll_elements/_leaves.njk', { |
||
| 52 | leaves: item.paidLeaves |
||
| 53 | }) |
||
| 54 | .template('pages/payroll_elements/_leaves.njk', { |
||
| 55 | leaves: item.unpaidLeaves |
||
| 56 | }) |
||
| 57 | .template('pages/payroll_elements/_leaves.njk', { |
||
| 58 | leaves: item.sickLeaves |
||
| 59 | }) |
||
| 60 | .template('pages/payroll_elements/_leaves.njk', { |
||
| 61 | leaves: item.exceptionalLeaves |
||
| 62 | }) |
||
| 63 | .build(); |
||
| 64 | |||
| 65 | rows.push(row); |
||
| 66 | } |
||
| 67 | |||
| 68 | return new Table(columns, rows); |
||
| 69 | } |
||
| 71 |