Passed
Pull Request — master (#99)
by Sergei
02:24
created

getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Widget;
6
7
use Throwable;
8
use Yiisoft\Definitions\Exception\NotInstantiableException;
9
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
10
11
final class NotInstantiableWithoutWidgetFactoryInitializationException
12
    extends NotInstantiableException
13
    implements FriendlyExceptionInterface
14
{
15 1
    public function __construct(private ?Throwable $previous)
16
    {
17 1
        parent::__construct(
18 1
            $previous->getMessage() .
0 ignored issues
show
Bug introduced by
The method getMessage() does not exist on null. ( Ignorable by Annotation )

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

18
            $previous->/** @scrutinizer ignore-call */ 
19
                       getMessage() .

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19 1
            ' Perhaps need initialize "WidgetFactory" with container for resolve dependencies.',
20 1
            previous: $previous,
21 1
        );
22
    }
23
24 1
    public function getName(): string
25
    {
26 1
        return 'Failed to create a widget. ' . $this->previous->getMessage();
0 ignored issues
show
Bug introduced by
The method getMessage() does not exist on null. ( Ignorable by Annotation )

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

26
        return 'Failed to create a widget. ' . $this->previous->/** @scrutinizer ignore-call */ getMessage();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
    }
28
29
    public function getSolution(): ?string
30
    {
31
        return <<<'SOLUTION'
32
            Perhaps need initialize `WidgetFactory` with container for resolve dependencies.
33
34
            To initialize the widget factory call `WidgetFactory::initialize()` before using the widget.
35
            It is a good idea to do that for the whole application.
36
37
            Example:
38
39
            ```php
40
            /**
41
             * @var Psr\Container\ContainerInterface $container
42
             */
43
44
            Yiisoft\Widget\WidgetFactory::initialize(
45
                container: $container,
46
                definitions: [MyWidget::class => new MyWidget(/*...*/)],
47
                themes: [
48
                    'custom' => [
49
                        MyWidget::class => [
50
                            'setValue()' => [42],
51
                        ],
52
                    ],
53
                ],
54
                validate: true, // Whether definitions need to be validated.
55
            );
56
            ```
57
58
            See Yii example in the configuration file of this package `config/bootstrap.php`.
59
            SOLUTION;
60
    }
61
}
62