Passed
Push — master ( 7bf385...40cf15 )
by Wilmer
57s queued 13s
created

FormModelNotSetException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 16
ccs 5
cts 5
cp 1
rs 10
wmc 4

3 Methods

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