AbstractRule::isSatisfiedBy()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace GameDomain\Rule;
4
5
use GameDomain\Round\Step\Answer;
6
use GameDomain\Exceptions\IrrelevantRuleException;
7
8
/**
9
 * Rule
10
 */
11
abstract class AbstractRule
12
{
13
    /**
14
     * @param \GameDomain\Round\Step\Answer $playerAnswer
15
     * @param int                           $number
16
     *
17
     * @return bool
18
     */
19
    final public function isSatisfiedBy(Answer $playerAnswer, $number)
20
    {
21
        try {
22
            return $playerAnswer->isSameAs($this->generateValidAnswer($number));
23
        } catch (IrrelevantRuleException $exception) {
24
            return false;
25
        }
26
    }
27
28
    /**
29
     * @param int $number
30
     *
31
     * @return \GameDomain\Round\Step\Answer
32
     * @throws \GameDomain\Exceptions\IrrelevantRuleException
33
     */
34
    abstract public function generateValidAnswer($number);
35
}
36