JohnDoe   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 4
Metric Value
wmc 4
cbo 4
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A play() 0 8 2
A __toString() 0 4 1
1
<?php
2
3
namespace FizzBuzzDomain\Players;
4
5
use GameDomain\Player\PlayerInterface;
6
use GameDomain\Round\Step\Answer;
7
use GameDomain\Round\Step\Step;
8
use GameDomain\Rule\AbstractRulesSet;
9
use Utils\NumberGenerator\NumberGeneratorInterface;
10
11
/**
12
 * Standard Player: this player usually answers correctly, but sometimes fails.
13
 */
14
final class JohnDoe implements PlayerInterface
15
{
16
    /** @var \Utils\NumberGenerator\NumberGeneratorInterface */
17
    protected $numberGenerator;
18
19
    /**
20
     * @param \Utils\NumberGenerator\NumberGeneratorInterface $numberGenerator
21
     */
22
    public function __construct(NumberGeneratorInterface $numberGenerator)
23
    {
24
        $this->numberGenerator = $numberGenerator;
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30
    public function play(AbstractRulesSet $gameRules, Step $step)
31
    {
32
        if (0 === $this->numberGenerator->generate(0, 1)) {
33
            return new Answer('?');
34
        }
35
36
        return $gameRules->generateValidAnswer($step->getRawValue());
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function __toString()
43
    {
44
        return 'John Doe';
45
    }
46
}
47