Completed
Push — 1.x ( 51200d...37ba08 )
by Akihito
8s
created

OnFailureMethodHandler::handle()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 10
cp 0.8
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 5
nop 3
crap 5.2
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 2
    public function handle(AbstractValidation $formValidation, MethodInvocation $invocation, AbstractForm $form)
22
    {
23 2
        unset($form);
24 2
        $args = (array) $invocation->getArguments();
25 2
        $object = $invocation->getThis();
26 2
        if (! $formValidation instanceof FormValidation) {
27
            throw new InvalidOnFailureMethod(get_class($invocation->getThis()));
28
        }
29 2
        $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 2
        if (! $formValidation instanceof FormValidation || ! method_exists($object, $onFailureMethod)) {
31
            throw new InvalidOnFailureMethod(get_class($invocation->getThis()));
32
        }
33
34 2
        return call_user_func_array([$invocation->getThis(), $onFailureMethod], $args);
35
    }
36
}
37