Completed
Push — 1.x ( 54a263...51200d )
by Akihito
04:04
created

OnFailureMethodHandler::handle()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 5
nop 3
crap 30
1
<?php
2
/**
3
 * This file is part of the Ray.WebFormModule package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\WebFormModule;
8
9
use Ray\Aop\MethodInvocation;
10
use Ray\WebFormModule\Annotation\AbstractValidation;
11
use Ray\WebFormModule\Annotation\FormValidation;
12
use Ray\WebFormModule\Exception\InvalidOnFailureMethod;
13
14
final class OnFailureMethodHandler implements FailureHandlerInterface
15
{
16
    const FAILURE_SUFFIX = 'ValidationFailed';
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function handle(AbstractValidation $formValidation, MethodInvocation $invocation, AbstractForm $form)
22
    {
23
        unset($form);
24
        $args = (array) $invocation->getArguments();
25
        $object = $invocation->getThis();
26
        if (! $formValidation instanceof FormValidation) {
27
            throw new InvalidOnFailureMethod(get_class($invocation->getThis()));
28
        }
29
        $onFailureMethod = $formValidation->onFailure ?: $invocation->getMethod()->getName() . self::FAILURE_SUFFIX;
0 ignored issues
show
Bug introduced by
Consider using $invocation->getMethod()->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
30
        if (! $formValidation instanceof FormValidation || ! method_exists($object, $onFailureMethod)) {
31
            throw new InvalidOnFailureMethod(get_class($invocation->getThis()));
32
        }
33
34
        return call_user_func_array([$invocation->getThis(), $onFailureMethod], $args);
35
    }
36
}
37