PdfOptimizerJobData::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 10
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 Mostafaznv\PdfOptimizer\DTOs;
4
5
use Illuminate\Support\Str;
6
use Mostafaznv\PdfOptimizer\Laravel\Concerns\Disk;
7
use Mostafaznv\PdfOptimizer\Laravel\Concerns\File;
8
use Psr\Log\LoggerInterface;
9
10
11
readonly class PdfOptimizerJobData
12
{
13
    public function __construct(
14
        public string           $id,
15
        public array            $commands,
16
        public string           $input,
17
        public string           $output,
18
        public ?File            $file = null,
19
        public ?Disk            $disk = null,
20
        public ?LoggerInterface $logger = null,
21
        public int              $timeout = 900
22
    ) {}
23
24
    public static function make(array $commands, string $input, string $output, File $file, ?Disk $disk = null, ?LoggerInterface $logger = null, int $timeout = 900): self
25
    {
26
        $id = Str::orderedUuid()->toString();
27
28
        return new self($id, $commands, $input, $output, $file, $disk, $logger, $timeout);
29
    }
30
}
31