Completed
Pull Request — master (#391)
by Marco
07:35
created

finalClassNotSupported()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
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
11
/**
12
 * Exception for invalid proxied classes
13
 *
14
 * @author Marco Pivetta <[email protected]>
15
 * @license MIT
16
 */
17
class InvalidProxiedClassException extends InvalidArgumentException implements ExceptionInterface
18
{
19 1
    public static function interfaceNotSupported(ReflectionClass $reflection) : self
20
    {
21 1
        return new self(sprintf('Provided interface "%s" cannot be proxied', $reflection->getName()));
22
    }
23
24 1
    public static function finalClassNotSupported(ReflectionClass $reflection) : self
25
    {
26 1
        return new self(sprintf('Provided class "%s" is final and cannot be proxied', $reflection->getName()));
27
    }
28
29 3
    public static function abstractProtectedMethodsNotSupported(ReflectionClass $reflection) : self
30
    {
31 3
        return new self(sprintf(
32 3
            'Provided class "%s" has following protected abstract methods, and therefore cannot be proxied:' . "\n%s",
33 3
            $reflection->getName(),
34 3
            implode(
35 3
                "\n",
36 3
                array_map(
37
                    function (ReflectionMethod $reflectionMethod) : string {
38 1
                        return $reflectionMethod->getDeclaringClass()->getName() . '::' . $reflectionMethod->getName();
39 3
                    },
40 3
                    array_filter(
41 3
                        $reflection->getMethods(),
42 3
                        function (ReflectionMethod $method) : bool {
43 3
                            return $method->isAbstract() && $method->isProtected();
44 3
                        }
45
                    )
46
                )
47
            )
48
        ));
49
    }
50
}
51