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

FormModelNotSetException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
dl 0
loc 15
ccs 0
cts 6
cp 0
rs 10
c 1
b 0
f 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getName() 0 3 1
A getSolution() 0 3 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