Round   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 6
Metric Value
wmc 5
cbo 6
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A play() 0 15 3
A createStep() 0 4 1
A createStepResult() 0 9 1
1
<?php
2
3
namespace FizzBuzzDomain;
4
5
use GameDomain\Player\PlayerInterface;
6
use GameDomain\Round\AbstractRound;
7
use GameDomain\Round\Step\Step;
8
use GameDomain\Round\Step\StepResult;
9
use GameDomain\Round\Step\StepResultCollection;
10
use GameDomain\Rule\AbstractRulesSet;
11
12
/**
13
 * Round
14
 */
15
final class Round extends AbstractRound
16
{
17
    /**
18
     * {@inheritDoc}
19
     */
20
    public function play(AbstractRulesSet $gameRules)
21
    {
22
        $roundResult = new StepResultCollection();
23
24
        foreach ($this->players as $player) {
25
            $stepResult = $this->createStepResult($gameRules, $player, $this->createStep());
26
            $roundResult->add($stepResult);
27
28
            if (!$stepResult->isValid()) {
29
                break;
30
            }
31
        }
32
33
        return $roundResult;
34
    }
35
36
    /**
37
     * @return \GameDomain\Round\Step\Step
38
     */
39
    protected function createStep()
40
    {
41
        return new Step($this->players->getPosition() + 1);
42
    }
43
44
    /**
45
     * @param \GameDomain\Rule\AbstractRulesSet  $gameRules
46
     * @param \GameDomain\Player\PlayerInterface $player
47
     * @param \GameDomain\Round\Step\Step        $step
48
     *
49
     * @return \GameDomain\Round\Step\StepResult
50
     */
51
    protected function createStepResult(AbstractRulesSet $gameRules, PlayerInterface $player, Step $step)
52
    {
53
        return new StepResult(
54
            $player,
55
            $player->play($gameRules, $step),
56
            $gameRules->generateValidAnswer($step->getRawValue()),
57
            $step
58
        );
59
    }
60
}
61