Completed
Branch Bowlingkata/Albert (8d392f)
by Albert
06:38
created

RollValue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromChar() 0 13 3
A value() 0 4 1
1
<?php
2
3
namespace Kata\BowlingKata;
4
5
final class RollValue
6
{
7
    const EMPTY = '-';
8
    const SPARE = '/';
9
    const STRIKE = 'X';
10
11
    /** @var int */
12
    private $value;
13
14
    private function __construct(int $value)
15
    {
16
        $this->value = $value;
17
    }
18
19
    public static function fromChar($char)
20
    {
21
        if (in_array($char, [self::EMPTY, self::SPARE]))
22
        {
23
            return new self(0);
24
        }
25
        if (self::STRIKE == $char)
26
        {
27
            return new self(10);
28
        }
29
30
        return new self($char);
31
    }
32
33
    public function value()
34
    {
35
        return $this->value;
36
    }
37
}
38