NotCallableException   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 13
c 3
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B fromInvalidCallable() 0 17 7
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of PHP Invoker.
7
 *
8
 * PHP version 7.1 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace DivineNii\Invoker\Exceptions;
19
20
/**
21
 * The given callable is not actually callable.
22
 *
23
 * @author Matthieu Napoli <[email protected]>
24
 */
25
class NotCallableException extends InvocationException
26
{
27
    /**
28
     * @param mixed      $value
29
     * @param bool       $containerEntry
30
     * @param \Throwable $previous
31
     *
32
     * @return InvocationException
33
     */
34 23
    public static function fromInvalidCallable($value, bool $containerEntry = false, $previous = null): InvocationException
35
    {
36 23
        if (\is_object($value)) {
37 2
            $message = \sprintf('Instance of %s is not a callable', \get_class($value));
38 21
        } elseif (\is_array($value) && isset($value[0], $value[1])) {
39 14
            $class   = \is_object($value[0]) ? \get_class($value[0]) : $value[0];
40 14
            $extra   = \method_exists($class, '__call') ? ' A __call() method exists but magic methods are not supported.' : '';
41 14
            $message = \sprintf('%s::%s() is not a callable.%s', $class, $value[1], $extra);
42
        } else {
43 8
            if ($containerEntry) {
44 3
                $message = \var_export($value, true) . ' is neither a callable nor a valid container entry';
45
            } else {
46 5
                $message = \var_export($value, true) . ' is not a callable';
47
            }
48
        }
49
50 23
        return new self($message, 0, $previous);
51
    }
52
}
53