Passed
Push — master ( c6092e...2f4692 )
by Thomas
43s
created

RadioField::addOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Webfactor\Laravel\Backpack\FluentSyntax\Fields;
4
5
use Webfactor\Laravel\Backpack\FluentSyntax\Contracts\CrudFieldAbstract;
6
use Webfactor\Laravel\Backpack\FluentSyntax\Traits\Defaultable;
7
use Webfactor\Laravel\Backpack\FluentSyntax\Traits\Prefixable;
8
use Webfactor\Laravel\Backpack\FluentSyntax\Traits\Suffixable;
9
10
class RadioField extends CrudFieldAbstract
11
{
12
    use Hintable, Defaultable;
13
14
    protected $type = 'radio';
15
16
    /**
17
     * Set options for the fields
18
     * @param  array  $options array of option
19
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use RadioField.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
20
     */
21
    public function options(array $options)
22
    {
23
      $this->options['options'] = $options;
24
25
      return $this;
26
    }
27
28
    /**
29
     * Add option to a field that is already set
30
     * @param string $value text that is shown to the user
31
     * @param null|string $key   the value of the new text
32
     */
33
    public function addOption($value, $key = null)
34
    {
35
      if(is_null($key)) {
36
        $this->options['options'][] = $value;
37
      } else {
38
        $this->options['options'][$key] = $value;
39
      }
40
41
      return $this;
42
    }
43
44
}
45