CrosswordDto::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Crossword\Features\Constructor;
6
7
use JsonSerializable;
8
9
/**
10
 * @psalm-immutable
11
 */
12
final class CrosswordDto implements JsonSerializable
13
{
14
    /**
15
     * @var LineDto[]
16
     */
17
    private array $lines;
18
19
    public function __construct(LineDto ...$lines)
20
    {
21
        $this->lines = $lines;
22
    }
23
24
    public function withLine(LineDto $line): self
25
    {
26
        return new self($line, ...$this->lines);
27
    }
28
29
    /**
30
     * @psalm-suppress ImpureFunctionCall
31
     */
32
    public function jsonSerialize(): array
33
    {
34
        return array_map(static fn (LineDto $line): array => $line->jsonSerialize(), $this->lines);
35
    }
36
}
37