DictionaryWordDto::__construct()   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 1
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\Dictionary;
6
7
use Countable;
8
9
/**
10
 * @psalm-immutable
11
 */
12
final class DictionaryWordDto implements Countable
13
{
14
    private array $payload;
15
16
    public function __construct(array $payload)
17
    {
18
        $this->payload = $payload;
19
    }
20
21
    public function count(): int
22
    {
23
        return $this->payload['success'] ? 1 : 0;
24
    }
25
26
    public function word(): string
27
    {
28
        return $this->isSuccess() ? $this->payload['data'][0]['word'] : '';
29
    }
30
31
    public function definition(): string
32
    {
33
        return $this->isSuccess() ? $this->payload['data'][0]['definition'] : '';
34
    }
35
36
    private function isSuccess(): bool
37
    {
38
        return (bool) $this->payload['success'];
39
    }
40
}
41