ExceptionResponder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A respond() 0 10 3
1
<?php
2
3
namespace Peridot\Leo\Responder;
4
5
use Exception;
6
use Peridot\Leo\Formatter\FormatterInterface;
7
use Peridot\Leo\Matcher\Match;
8
use Peridot\Leo\Matcher\Template\TemplateInterface;
9
use Peridot\Leo\Responder\Exception\AssertionException;
10
11
/**
12
 * The ExceptionResponder responds to a match by throwing an exception
13
 * on a failed match.
14
 *
15
 * @package Peridot\Leo\Responder
16
 */
17
class ExceptionResponder implements ResponderInterface
18
{
19
    /**
20
     * @var FormatterInterface
21
     */
22
    protected $formatter;
23
24
    /**
25
     * @param FormatterInterface $formatter
26
     */
27
    public function __construct(FormatterInterface $formatter)
28
    {
29
        $this->formatter = $formatter;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     *
35
     * Throws an exception containing the formatted message.
36
     *
37
     * @param  Match             $match
38
     * @param  TemplateInterface $template
39
     * @param  string            $message
40
     * @return void
41
     * @throws Exception
42
     */
43
    public function respond(Match $match, TemplateInterface $template, $message = '')
44
    {
45
        if ($match->isMatch()) {
46
            return;
47
        }
48
49
        $this->formatter->setMatch($match);
50
        $message = ($message) ? $message : $this->formatter->getMessage($template);
51
        throw new AssertionException($message);
52
    }
53
}
54