DictionaryWordDto   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 27
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A word() 0 3 2
A definition() 0 3 2
A __construct() 0 3 1
A isSuccess() 0 3 1
A count() 0 3 2
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