Completed
Push — unit-tests-conditions ( fc6a80...b4e1a6 )
by Romain
02:09
created

FormzException   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getNewExceptionInstance() 0 12 1
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 Formz project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Exceptions;
15
16
use TYPO3\CMS\Extbase\Reflection\ClassReflection;
17
18
/**
19
 * A generic Formz exception.
20
 */
21
abstract class FormzException extends \Exception
22
{
23
    /**
24
     * Creates a new exception instance.
25
     *
26
     * The code will be fetched from the calling method's `@code` property.
27
     *
28
     * @param string $message
29
     * @param array  $arguments
30
     * @return FormzException
31
     */
32
    final protected static function getNewExceptionInstance($message, array $arguments = [])
33
    {
34
        $exceptionClassName = get_called_class();
35
        $methodName = ucfirst(debug_backtrace()[1]['function']);
36
        $reflection = new ClassReflection($exceptionClassName);
37
        $exceptionCode = end($reflection->getMethod($methodName)->getTagValues('code'));
0 ignored issues
show
Bug introduced by
$reflection->getMethod($...)->getTagValues('code') cannot be passed to end() as the parameter $array expects a reference.
Loading history...
38
39
        return new $exceptionClassName(
40
            vsprintf($message, $arguments),
41
            $exceptionCode
42
        );
43
    }
44
}
45