interfaceNotSupported()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Exception;
6
7
use InvalidArgumentException;
8
use ReflectionClass;
9
use ReflectionMethod;
10
use function array_filter;
11
use function array_map;
12
use function implode;
13
use function sprintf;
14
15
/**
16
 * Exception for invalid proxied classes
17
 */
18
class InvalidProxiedClassException extends InvalidArgumentException implements ExceptionInterface
19
{
20
    public static function interfaceNotSupported(ReflectionClass $reflection) : self
21 1
    {
22
        return new self(sprintf('Provided interface "%s" cannot be proxied', $reflection->getName()));
23 1
    }
24
25
    public static function finalClassNotSupported(ReflectionClass $reflection) : self
26 1
    {
27
        return new self(sprintf('Provided class "%s" is final and cannot be proxied', $reflection->getName()));
28 1
    }
29
30
    public static function abstractProtectedMethodsNotSupported(ReflectionClass $reflection) : self
31 3
    {
32
        return new self(sprintf(
33 3
            'Provided class "%s" has following protected abstract methods, and therefore cannot be proxied:' . "\n%s",
34 3
            $reflection->getName(),
35 3
            implode(
36 3
                "\n",
37 3
                array_map(
38 3
                    static function (ReflectionMethod $reflectionMethod) : string {
39
                        return $reflectionMethod->getDeclaringClass()->getName() . '::' . $reflectionMethod->getName();
40 1
                    },
41 3
                    array_filter(
42 3
                        $reflection->getMethods(),
43 3
                        static function (ReflectionMethod $method) : bool {
44
                            return $method->isAbstract() && $method->isProtected();
45 3
                        }
46 3
                    )
47
                )
48
            )
49
        ));
50
    }
51
}
52