Passed
Pull Request — master (#192)
by Alexander
05:43 queued 02:47
created

FormModelNotSetException::getSolution()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Exception;
6
7
use InvalidArgumentException;
8
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
9
10
final class FormModelNotSetException extends InvalidArgumentException implements FriendlyExceptionInterface
11
{
12
    public function __construct()
13
    {
14
        parent::__construct($this->getName());
15
    }
16
17
    public function getName(): string
18
    {
19
        return 'Failed to create widget because form model is not set.';
20
    }
21
22
    public function getSolution(): ?string
23
    {
24
        return <<<SOLUTION
25
            You can configure the `FormModel::class` in two ways. The first way is through the widgets using the `for()`
26
        method `Text::widget()->for(FormModel::class, attribute)`, where the first argument is the `FormModel::class`.
27
        The second way is through the `Field::class` where in each field type the first argument is the
28
        `FormModel::class`, `Field::widget->text(FormModel::class, attribute)`.
29
        SOLUTION;
30
    }
31
}
32