InvalidProxiedClassException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 34
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A interfaceNotSupported() 0 4 1
A finalClassNotSupported() 0 4 1
A abstractProtectedMethodsNotSupported() 0 21 2
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