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