Passed
Pull Request — master (#192)
by Sergei
02:09
created

FieldTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hint() 0 3 1
A label() 0 3 1
A error() 0 3 1
A widget() 0 7 1
A text() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form;
6
7
use Yiisoft\Form\Field\Text;
8
use Yiisoft\Form\Field\Part\Error;
9
use Yiisoft\Form\Field\Part\Hint;
10
use Yiisoft\Form\Field\Part\Label;
11
12
trait FieldTrait
13
{
14 2
    public static function text(FormModelInterface $formModel, string $attribute, array $config = []): Text
15
    {
16 2
        return self::widget(Text::class, $formModel, $attribute, $config);
17
    }
18
19 2
    public static function label(FormModelInterface $formModel, string $attribute, array $config = []): Label
20
    {
21 2
        return FieldStaticFactory::factory()->label($formModel, $attribute, $config);
22
    }
23
24 2
    public static function hint(FormModelInterface $formModel, string $attribute, array $config = []): Hint
25
    {
26 2
        return FieldStaticFactory::factory()->hint($formModel, $attribute, $config);
27
    }
28
29 2
    public static function error(FormModelInterface $formModel, string $attribute, array $config = []): Error
30
    {
31 2
        return FieldStaticFactory::factory()->error($formModel, $attribute, $config);
32
    }
33
34
    /**
35
     * @psalm-template T
36
     * @psalm-param class-string<T> $class
37
     * @psalm-return T
38
     */
39 2
    public static function widget(
40
        string $class,
41
        FormModelInterface $formModel,
42
        string $attribute,
43
        array $config = []
44
    ): object {
45 2
        return FieldStaticFactory::factory()->widget($class, $formModel, $attribute, $config);
46
    }
47
}
48