Conditions | 1 |
Paths | 1 |
Total Lines | 66 |
Code Lines | 0 |
Lines | 0 |
Ratio | 0 % |
Tests | 1 |
CRAP Score | 1 |
Changes | 1 | ||
Bugs | 0 | Features | 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
11 | 1 | public function __construct( |
|
12 | public readonly bool $Moto, |
||
13 | public readonly string $Email, |
||
14 | public readonly string $Phone, |
||
15 | public readonly string $BankId, |
||
16 | public readonly bool $Systemic, |
||
17 | public readonly bool $Switching, |
||
18 | public readonly ?string $ParentId, |
||
19 | public readonly float $Amount, |
||
20 | public readonly string $ChannelId, |
||
21 | public readonly int $TerminalId, |
||
22 | public readonly string $MerchantId, |
||
23 | public readonly string $OrderCode, |
||
24 | public readonly ?string $ProductId, |
||
25 | public readonly TransactionStatus $StatusId, |
||
26 | public readonly string $FullName, |
||
27 | public readonly ?string $ResellerId, |
||
28 | public readonly string $InsDate, |
||
29 | public readonly float $TotalFee, |
||
30 | public readonly string $CardUniqueReference, |
||
31 | public readonly string $CardToken, |
||
32 | public readonly string $CardNumber, |
||
33 | public readonly float $TipAmount, |
||
34 | public readonly string $SourceCode, |
||
35 | public readonly string $SourceName, |
||
36 | public readonly ?float $Latitude, |
||
37 | public readonly ?float $Longitude, |
||
38 | public readonly string $CompanyName, |
||
39 | public readonly string $TransactionId, |
||
40 | public readonly string $CompanyTitle, |
||
41 | public readonly string $PanEntryMode, |
||
42 | public readonly int $ReferenceNumber, |
||
43 | public readonly ?string $ResponseCode, |
||
44 | public readonly string $CurrencyCode, |
||
45 | public readonly string $OrderCulture, |
||
46 | public readonly ?string $MerchantTrns, |
||
47 | public readonly string $CustomerTrns, |
||
48 | public readonly bool $IsManualRefund, |
||
49 | public readonly ?string $TargetPersonId, |
||
50 | public readonly ?string $TargetWalletId, |
||
51 | public readonly bool $LoyaltyTriggered, |
||
52 | public readonly TransactionType $TransactionTypeId, |
||
53 | public readonly int $TotalInstallments, |
||
54 | public readonly ?string $CardCountryCode, |
||
55 | public readonly ?string $CardIssuingBank, |
||
56 | public readonly int $RedeemedAmount, |
||
57 | public readonly ?int $ClearanceDate, |
||
58 | public readonly ?int $CurrentInstallment, |
||
59 | /** @var string[] */ |
||
60 | public readonly array $Tags, |
||
61 | public readonly ?string $BillId, |
||
62 | public readonly ?string $ResellerSourceCode, |
||
63 | public readonly ?string $ResellerSourceName, |
||
64 | public readonly ?string $ResellerCompanyName, |
||
65 | public readonly ?string $ResellerSourceAddress, |
||
66 | public readonly string $CardExpirationDate, |
||
67 | public readonly ?string $RetrievalReferenceNumber, |
||
68 | /** @var string[] */ |
||
69 | public readonly array $AssignedMerchantUsers, |
||
70 | /** @var string[] */ |
||
71 | public readonly array $AssignedResellerUsers, |
||
72 | public readonly int $CardTypeId, |
||
73 | public readonly ?int $DigitalWalletId, |
||
74 | public readonly ?string $ResponseEventId, |
||
75 | public readonly ?string $ElectronicCommerceIndicator, |
||
76 | ) { |
||
77 | } |
||
89 |
This check compares calls to functions or methods with their respective definitions. If the call has less 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. Please note the @ignore annotation hint above.