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

NonStringableObject   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 22
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromAttemptedToString() 0 10 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