Issues (84)

src/Traits/RenderableTrait.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * @package Application Utils
4
 * @subpackage Traits
5
 * @see \AppUtils\Traits\RenderableTrait
6
 */
7
8
declare(strict_types=1);
9
10
namespace AppUtils\Traits;
11
12
use AppUtils\Interfaces\RenderableInterface;
13
use Throwable;
14
15
/**
16
 * Trait used to quickly implement the interface
17
 * {@see RenderableInterface}: Only the `render()`
18
 * method needs to be implemented.
19
 *
20
 * @package Application Utils
21
 * @subpackage Traits
22
 * @author Sebastian Mordziol <[email protected]>
23
 *
24
 * @see RenderableInterface
25
 */
26
trait RenderableTrait
27
{
28
    public function display() : void
29
    {
30
        echo $this->render();
0 ignored issues
show
It seems like render() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        echo $this->/** @scrutinizer ignore-call */ render();
Loading history...
31
    }
32
33
    public function __toString() : string
34
    {
35
        try
36
        {
37
            return $this->render();
38
        }
39
        catch (Throwable $e)
40
        {
41
            return sprintf(
42
                'Exception while rendering [%s]: %s',
43
                get_class($this),
44
                $e->getMessage()
45
            );
46
        }
47
    }
48
}
49