getSolution()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 27
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 9.488
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