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

AttributeNotSetException   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 InvalidArgumentException;
8
use Throwable;
9
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
10
11
final class AttributeNotSetException extends InvalidArgumentException implements FriendlyExceptionInterface
12
{
13 1
    public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
14
    {
15 1
        $message = $message === '' ? $this->getName() : $message;
16 1
        parent::__construct($message, $code, $previous);
17
    }
18
19 1
    public function getName(): string
20
    {
21 1
        return 'Failed to create widget because "attribute" is not set.';
22
    }
23
24
    public function getSolution(): ?string
25
    {
26
        return <<<SOLUTION
27
            You can configure the `attribute` in two ways. The first way is through the widgets using the `for()`
28
        method `Text::widget()->for(FormModel::class, attribute)`, where the second argument is the `attribute`.
29
        The second way is through the `Field::class` where in each field type the second argument is the
30
        `attribute`, `Field::widget->text(FormModel::class, attribute)`.
31
        SOLUTION;
32
    }
33
}
34