Transaction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
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 19
dl 0
loc 21
ccs 1
cts 1
cp 1
crap 1
rs 10

How to fix   Many Parameters   

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\Responses;
4
5
use Sebdesign\VivaPayments\Enums\TransactionStatus;
6
use Sebdesign\VivaPayments\Enums\TransactionType;
7
8
class Transaction
9
{
10 1
    public function __construct(
11
        public readonly string $email,
12
        public readonly int $amount,
13
        public readonly string $orderCode,
14
        public readonly TransactionStatus $statusId,
15
        public readonly string $fullName,
16
        public readonly string $insDate,
17
        public readonly string $cardNumber,
18
        public readonly string $currencyCode,
19
        public readonly string $customerTrns,
20
        public readonly string $merchantTrns,
21
        public readonly TransactionType $transactionTypeId,
22
        public readonly bool $recurringSupport,
23
        public readonly int $totalInstallments,
24
        public readonly ?string $cardCountryCode,
25
        public readonly ?string $cardIssuingBank,
26
        public readonly int $currentInstallment,
27
        public readonly string $cardUniqueReference,
28
        public readonly int $cardTypeId,
29
        public readonly ?int $digitalWalletId = null,
30
    ) {
31
    }
32
33
    /** @phpstan-param  TransactionArray  $attributes */
34 3
    public static function create(array $attributes): self
35
    {
36 3
        return new self(...[
0 ignored issues
show
Bug introduced by
array($attributes, 'stat...['transactionTypeId'])) of type Sebdesign\VivaPayments\E...s\TransactionType|array is incompatible with the type string expected by parameter $email of Sebdesign\VivaPayments\R...nsaction::__construct(). ( Ignorable by Annotation )

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

36
        return new self(/** @scrutinizer ignore-type */ ...[
Loading history...
Bug introduced by
The call to Sebdesign\VivaPayments\R...nsaction::__construct() has too few arguments starting with amount. ( Ignorable by Annotation )

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

36
        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...
37
            ...$attributes,
38 3
            'statusId' => TransactionStatus::from($attributes['statusId']),
39 3
            'transactionTypeId' => TransactionType::from($attributes['transactionTypeId']),
40
        ]);
41
    }
42
}
43