Event::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 13
dl 0
loc 18
ccs 4
cts 4
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
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\Domain;
6
7
use InShore\Bookwhen\Domain\Location;
8
9
final class Event
10
{
11
    /**
12
     *
13
     */
14
    public int $attendeeAvailable;
15
16
    /**
17
     *
18
     */
19
    public bool $finished;
20
21
    /**
22
     *
23
     */
24
    public bool $soldOut;
25
26
    /**
27
     *
28
     *
29
     */
30 3
    public function __construct(
31
        public readonly bool $allDay,
32
        public readonly array $attachments,
33
        public readonly int $attendeeCount,
34
        public readonly int $attendeeLimit,
35
        public readonly string $details,
36
        public readonly string $endAt,
37
        public readonly string $id,
38
        public readonly Location $location,
39
        public readonly int $maxTicketsPerBooking,
40
        public readonly string $startAt,
41
        public readonly array $tickets,
42
        public readonly string $title,
43
        public readonly bool $waitingList
44
    ) {
45 3
        $this->attendeeAvailable = $this->attendeeLimit - $this->attendeeCount;
46 3
        $this->finished = false; // @todo
47 3
        $this->soldOut = ($this->attendeeCount === $this->attendeeLimit);
48
    }
49
}
50