Issues (11)

src/Components/HandlesDefaultAndOldValue.php (2 issues)

1
<?php
2
3
namespace ProtoneMedia\LaravelFormComponents\Components;
4
5
trait HandlesDefaultAndOldValue
6
{
7
    use HandlesBoundValues;
8
9
    private function setValue(
10
        string $name,
11
        $bind = null,
12
        $default = null,
13
        $language = null
14
    ) {
15
        if ($this->isWired()) {
0 ignored issues
show
It seems like isWired() 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

15
        if ($this->/** @scrutinizer ignore-call */ isWired()) {
Loading history...
16
            return;
17
        }
18
19
        $inputName = static::convertBracketsToDots($name);
20
21
        if (!$language) {
22
            $boundValue = $this->getBoundValue($bind, $name);
23
24
            $default = is_null($boundValue) ? $default : $boundValue;
25
26
            return $this->value = old($inputName, $default);
0 ignored issues
show
Bug Best Practice introduced by
The property value does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
        }
28
29
        if ($bind !== false) {
30
            $bind = $bind ?: $this->getBoundTarget();
31
        }
32
33
        if ($bind) {
34
            $default = $bind->getTranslation($name, $language, false) ?: $default;
35
        }
36
37
        $this->value = old("{$inputName}.{$language}", $default);
38
    }
39
}
40