WidgetFactoryInitializationException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 29
c 2
b 0
f 0
dl 0
loc 10
ccs 2
cts 2
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getSolution() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Widget;
6
7
use RuntimeException;
8
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
9
10
/**
11
 * @deprecated Will be removed in version 3.0.
12
 */
13
final class WidgetFactoryInitializationException extends RuntimeException implements FriendlyExceptionInterface
14
{
15 1
    public function getName(): string
16
    {
17 1
        return 'Failed to create a widget because WidgetFactory is not initialized.';
18
    }
19
20
    public function getSolution(): ?string
21
    {
22
        return <<<'SOLUTION'
23
To initialize the widget factory call `WidgetFactory::initialize()` before using the widget.
24
It is a good idea to do that for the whole application.
25
26
Example:
27
28
```php
29
/**
30
 * @var Psr\Container\ContainerInterface $container
31
 */
32
33
Yiisoft\Widget\WidgetFactory::initialize(
34
    container: $container,
35
    definitions: [MyWidget::class => new MyWidget(/*...*/)],
36
    themes: [
37
        'custom' => [
38
            MyWidget::class => [
39
                'setValue()' => [42],
40
            ],
41
        ],
42
    ],
43
    validate: true, // Whether definitions need to be validated.
44
);
45
```
46
47
See Yii example in the configuration file of this package `config/bootstrap.php`.
48
SOLUTION;
49
    }
50
}
51