Completed
Push — master ( e38edc...acf857 )
by Bram
02:11
created

UserOptionSetField::createField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
use Broarm\EventTickets\UserOptionSetFieldGridFieldConfig;
3
4
/**
5
 * Class UserOptionSetField
6
 *
7
 * @author Bram de Leeuw
8
 * @package UserTextField
9
 *
10
 * @method \HasManyList Options()
11
 */
12
class UserOptionSetField extends Broarm\EventTickets\UserField
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14
    private static $has_many = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $has_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
        'Options' => 'Broarm\EventTickets\UserFieldOption'
16
    );
17
18
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
19
    {
20
        $fields = parent::getCMSFields();
21
        if ($this->exists()) {
22
            $fields->addFieldToTab('Root.Main', GridField::create(
23
                'Options',
24
                _t('AttendeeExtraField.Options', 'Add field options'),
25
                $this->Options(),
26
                UserOptionSetFieldGridFieldConfig::create()
27
            ));
28
        }
29
30
        return $fields;
31
    }
32
33
    /**
34
     * @param string $fieldName
35
     * @param null   $defaultValue
36
     *
37
     * @return OptionsetField
38
     */
39
    public function createField($fieldName, $defaultValue = null)
40
    {
41
        return OptionsetField::create($fieldName, $this->Title, $this->Options()->map()->toArray(), $defaultValue);
42
    }
43
44
    /**
45
     * Get the value by set option
46
     *
47
     * @return mixed
48
     */
49
    public function getValue()
50
    {
51
        return $this->Options()->byID($this->getField('Value'))->Title;
52
    }
53
}
54