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

NonStringableObject::fromAttemptedToString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
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 Dont\Exception;
6
7
use LogicException;
8
9
class NonStringableObject extends LogicException implements ExceptionInterface
10
{
11
    private const ERROR_TEMPLATE = <<<'ERROR'
12
The given object %s#%s is not designed to be stringable.
13
14
You tried to access a method called "__toString()".
15
ERROR;
16
17
    /**
18
     * @return NonStringableObject
19
     */
20 2
    public static function fromAttemptedToString(object $object) : self
21
    {
22 2
        $className = get_class($object);
23
24 2
        return new self(sprintf(
25 2
            self::ERROR_TEMPLATE,
26
            $className,
27 2
            spl_object_hash($object)
28
        ));
29
    }
30
}
31