Completed
Push — master ( d43887...767130 )
by De Cramer
9s
created

BooleanField::getRawValueFromEntry()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace eXpansion\Framework\Config\Ui\Fields;
4
5
use eXpansion\Framework\Config\Model\BooleanConfig;
6
use eXpansion\Framework\Config\Model\ConfigInterface;
7
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
8
use eXpansion\Framework\Core\Plugins\Gui\ManialinkFactory;
9
use eXpansion\Framework\Gui\Ui\Factory;
10
use FML\Types\Renderable;
11
12
/**
13
 * Class TextField
14
 *
15
 * @author    de Cramer Oliver<[email protected]>
16
 * @copyright 2018 eXpansion
17
 * @package eXpansion\Framework\Config\Ui
18
 */
19
class BooleanField implements UiInterface
20
{
21
    /** @var Factory */
22
    protected $uiFactory;
23
24
    /**
25
     * TextField constructor.
26
     *
27
     * @param Factory $uiFactory
28
     */
29
    public function __construct(Factory $uiFactory)
30
    {
31
        $this->uiFactory = $uiFactory;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function build(ConfigInterface $config, $width, ManialinkInterface $manialink, ManialinkFactory $manialinkFactory): Renderable
38
    {
39
40
        if ($config->get()) {
41
            $selectedIndex = 0;
42
        } else {
43
            $selectedIndex = 1;
44
        }
45
46
        return $this
47
            ->uiFactory
48
            ->createDropdown($config->getPath(), ["True" => "true", "False" => "false"], $selectedIndex, false)
49
            ->setWidth($width);
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function isCompatible(ConfigInterface $config): bool
56
    {
57
        return ($config instanceof BooleanConfig);
0 ignored issues
show
Bug introduced by
The class eXpansion\Framework\Config\Model\BooleanConfig does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
58
    }
59
60
    /**
61
     * Get raw value to set from gui entry data.
62
     *
63
     * @param ConfigInterface $config
64
     * @param                 $entry
65
     *
66
     * @return mixed
67
     */
68
    public function getRawValueFromEntry(ConfigInterface $config, $entry)
69
    {
70
        return $entry;
71
    }
72
}
73