Test Failed
Pull Request — master (#159)
by Alexander
02:49
created

PlaceholderTrait::doNotSetPlaceholder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Field\Base;
6
7
use Yiisoft\Html\Tag\Base\Tag;
8
9
trait PlaceholderTrait
10
{
11
    private ?string $placeholder = null;
12
    private bool $setPlaceholder = true;
13
14
    public function placeholder(?string $placeholder): self
15
    {
16
        $new = clone $this;
17
        $new->placeholder = $placeholder;
18
        return $new;
19
    }
20
21
    public function doNotSetPlaceholder(): self
22
    {
23
        $new = clone $this;
24
        $new->setPlaceholder = false;
25
        return $new;
26
    }
27
28
    protected function preparePlaceholderInInputTag(Tag $tag): Tag
29
    {
30
        if (
31
            $this->setPlaceholder
32
            && $tag->getAttribute('placeholder') === null
0 ignored issues
show
Bug introduced by
The method getAttribute() does not exist on Yiisoft\Html\Tag\Base\Tag. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
            && $tag->/** @scrutinizer ignore-call */ getAttribute('placeholder') === null

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
        ) {
34
            $placeholder = $this->placeholder ?? $this->getAttributePlaceholder();
0 ignored issues
show
Bug introduced by
It seems like getAttributePlaceholder() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
            $placeholder = $this->placeholder ?? $this->/** @scrutinizer ignore-call */ getAttributePlaceholder();
Loading history...
35
            if ($placeholder !== null) {
36
                $tag = $tag->attribute('placeholder', $placeholder);
37
            }
38
        }
39
40
        return $tag;
41
    }
42
}
43