TransactionPaymentCreated::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 66
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 61
dl 0
loc 66
ccs 1
cts 1
cp 1
crap 1
rs 10

How to fix   Long Method    Many Parameters   

Long Method

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:

Many Parameters

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
2
3
namespace Sebdesign\VivaPayments\Events;
4
5
use Sebdesign\VivaPayments\Enums\TransactionStatus;
6
use Sebdesign\VivaPayments\Enums\TransactionType;
7
8
/** @see https://developer.vivawallet.com/webhooks-for-payments/transaction-payment-created/ */
9
class TransactionPaymentCreated
10
{
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
    }
78
79
    /** @phpstan-param  TransactionPaymentCreatedArray  $attributes */
80 3
    public static function create(array $attributes): self
81
    {
82 3
        return new self(...[
0 ignored issues
show
Bug introduced by
The call to Sebdesign\VivaPayments\E...tCreated::__construct() has too few arguments starting with Email. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
        return /** @scrutinizer ignore-call */ new self(...[

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.

Loading history...
Bug introduced by
array($attributes, 'Stat...['TransactionTypeId'])) of type Sebdesign\VivaPayments\E...s\TransactionType|array is incompatible with the type boolean expected by parameter $Moto of Sebdesign\VivaPayments\E...tCreated::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
        return new self(/** @scrutinizer ignore-type */ ...[
Loading history...
83
            ...$attributes,
84 3
            'StatusId' => TransactionStatus::from($attributes['StatusId']),
85 3
            'TransactionTypeId' => TransactionType::from($attributes['TransactionTypeId']),
86
        ]);
87
    }
88
}
89