Completed
Pull Request — master (#10)
by
unknown
33:07
created

NonCallableObject::fromAttemptedCall()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 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
    public static function fromAttemptedCall($object, string $method) : self
24
    {
25
        if (! is_object($object)) {
26
            throw TypeError::fromNonObject($object);
27
        }
28
29
        $className = get_class($object);
30
31
        return new self(sprintf(
32
            self::ERROR_TEMPLATE,
33
            $className,
34
            spl_object_hash($object),
35
            $method
36
        ));
37
    }
38
}
39