Completed
Pull Request — master (#19)
by Oskar
01:54
created

NonCallableObject   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 30
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromAttemptedCall() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dont\Exception;
6
7
use LogicException;
8
9
class NonCallableObject extends LogicException implements ExceptionInterface
10
{
11
    private const ERROR_TEMPLATE = <<<'ERROR'
12
The given object %s#%s is not designed to allow any undefined or inaccessible methods to be called.
13
14
You tried to call a method called "%s".
15
16
Perhaps you made a typo in the method name, or tried to call an inaccessible method?
17
ERROR;
18
19
    /**
20
     * @param object $object
21
     * @throws TypeError
22
     */
23 2
    public static function fromAttemptedCall($object, string $method) : self
24
    {
25 2
        if (! is_object($object)) {
26
            throw TypeError::fromNonObject($object);
27
        }
28
29 2
        $className = get_class($object);
30
31 2
        return new self(sprintf(
32 2
            self::ERROR_TEMPLATE,
33
            $className,
34 2
            spl_object_hash($object),
35
            $method
36
        ));
37
    }
38
}
39