Completed
Push — master ( efc908...2ccc8e )
by Jose Luis
03:00
created

SelectFieldType::getColumnType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\Field\Select;
4
5
use Styde\Html\Facades\Field;
6
use Hechoenlaravel\JarvisFoundation\Field\FieldTypeInterface;
7
use Hechoenlaravel\JarvisFoundation\Field\FieldTypeImplementationTrait;
8
9
/**
10
 * Class SelectFieldType
11
 * @package Hechoenlaravel\JarvisFoundation\Field\Text
12
 */
13
class SelectFieldType implements FieldTypeInterface
14
{
15
    use FieldTypeImplementationTrait;
16
17
    /**
18
     * @var
19
     */
20
    private $value;
21
22
    /**
23
     * @var string
24
     */
25
    protected $columnType = "string";
26
27
    /**
28
     * The field type name
29
     * @var string
30
     */
31
    public $name = "Lista de selección";
32
33
    /**
34
     * The field slug for the instance
35
     * @var
36
     */
37
    public $fieldSlug;
38
39
    /**
40
     * The field Name for the instance
41
     * @var
42
     */
43
    public $fieldName;
44
45
    /**
46
     * The field description for the instance
47
     * @var
48
     */
49
    public $fieldDescription;
50
51
    /**
52
     * The field Options for the Instance
53
     * @var
54
     */
55
    public $fieldOptions;
56
57
    /**
58
     * Validation rules for the field type
59
     * @var array
60
     */
61
    public $validationRules = [''];
62
63
    /**
64
     * get the column type for this field type
65
     * @return string
66
     */
67
    public function getColumnType()
68
    {
69
        return $this->columnType;
70
    }
71
72
    /**
73
     * Set a value for this field;
74
     * @param $value
75
     */
76
    public function setValue($value)
77
    {
78
        $this->value = $value;
79
    }
80
81
82
    /**
83
     * get the value for the field
84
     * @return mixed
85
     */
86
    public function getValue()
87
    {
88
        return $this->value;
89
    }
90
91
    /**
92
     * return the form view
93
     * @return mixed
94
     */
95
    public function present()
96
    {
97
        $options = [];
98
        foreach(unserialize($this->fieldOptions) as $o)
99
        {
100
            $options[$o] = $o;
101
        }
102
        return Field::select($this->fieldSlug, $options , $this->value, ['label' => $this->fieldName, 'class' => 'select2']);
103
    }
104
105
    /**
106
     * Que the form for the options of the field type
107
     * @return mixed
108
     */
109
    public function getOptionsForm()
110
    {
111
        return view('jarvisPlatform::field.types.select.optionsForm')->render();
0 ignored issues
show
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
112
    }
113
}
114