Passed
Push — master ( 35eebd...7b8a1a )
by Roman
16:45
created

GamePlay::__construct()   A

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\Game\Features\GamePlay;
6
7
use App\Game\Features\GamePlay\Crossword\CrosswordConstructor;
8
use App\Game\Features\GamePlay\Crossword\CrosswordCriteria;
9
use App\Game\Features\GamePlay\Crossword\GameDto;
10
use App\Game\Features\GamePlay\Crossword\Grid;
11
12
final class GamePlay
13
{
14
    private CrosswordConstructor $constructor;
15
16
    public function __construct(CrosswordConstructor $constructor)
17
    {
18
        $this->constructor = $constructor;
19
    }
20
21 1
    public function new(string $language, string $type, int $wordCount): GameDto
22
    {
23 1
        $crossword = $this->constructor->construct(new CrosswordCriteria($language, $type, $wordCount));
24 1
        $grid = new Grid($crossword);
25 1
        $definitions = array_map(static fn (array $item) => $item['word']['definition'], $crossword);
26 1
        foreach ($crossword as $index => $line) {
27 1
            foreach ($line['line'] as $number => $cell) {
28 1
                $grid->fillLetter($cell);
29 1
                $grid->fillCrossLineNumbers($cell, $index);
30 1
                0 === $number && $grid->fillLineNumbers($cell, $index);
31
            }
32
        }
33
34 1
        return new GameDto($grid->field(), $grid->size(), $definitions);
35
    }
36
}
37