Completed
Push — master ( 9a42b3...71797f )
by Song
02:37
created

HasValuePicker::pickMultiple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Admin;
6
use Encore\Admin\Form\Field;
7
use Illuminate\Support\Arr;
8
9
/**
10
 * @mixin Field
11
 */
12
trait HasValuePicker
13
{
14
    /**
15
     * @var ValuePicker
16
     */
17
    protected $picker;
18
19
    /**
20
     * @param string $picker
21
     * @param string $column
22
     * @return $this
23
     */
24
    public function pick($picker, $column = '')
25
    {
26
        $this->picker = new ValuePicker($picker, $column);
27
28
        return $this;
29
    }
30
31
    /**
32
     * @param string $picker
33
     * @param string $column
34
     * @param string $separator
35
     */
36
    public function pickMany($picker, $column = '', $separator = ';')
37
    {
38
        $this->picker = new ValuePicker($picker, $column, true, $separator);
39
40
        return $this;
41
    }
42
43
    /**
44
     * @param \Closure|null $callback
45
     * @return $this
46
     */
47
    protected function mountPicker(\Closure $callback = null)
48
    {
49
        $this->picker && $this->picker->mount($this, $callback);
50
51
        return $this;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    protected function getRules()
58
    {
59
        $rules = parent::getRules();
60
61
        array_delete($rules, 'image');
62
63
        return $rules;
64
    }
65
66
    /**
67
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
68
     */
69
    protected function renderFilePicker()
70
    {
71
        $this->mountPicker()
0 ignored issues
show
Bug introduced by
It seems like setView() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
72
            ->setView('admin::form.filepicker')
73
            ->attribute('type', 'text')
74
            ->attribute('id', $this->id)
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
75
            ->attribute('name', $this->elementName ?: $this->formatName($this->column))
0 ignored issues
show
Bug introduced by
The property elementName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property column does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
It seems like formatName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
76
            ->attribute('value', old($this->elementName ?: $this->column, $this->value()))
0 ignored issues
show
Bug introduced by
It seems like value() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
77
            ->attribute('class', 'form-control '.$this->getElementClassString())
0 ignored issues
show
Bug introduced by
It seems like getElementClassString() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
78
            ->attribute('placeholder', $this->getPlaceholder())
0 ignored issues
show
Bug introduced by
It seems like getPlaceholder() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
79
            ->addVariables([
80
                'preview' => $this->picker->getPreview(get_called_class()),
81
            ]);
82
83
        return Admin::component('admin::form.filepicker', $this->variables());
0 ignored issues
show
Bug introduced by
It seems like variables() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
84
    }
85
}
86