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

GamePlay::new()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 4
nop 3
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 4
rs 9.9332
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