Completed
Pull Request — master (#280)
by
unknown
03:35
created

BooleanField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 41
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 14 2
A isCompatible() 0 4 1
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\Gui\Ui\Factory;
8
use FML\Types\Renderable;
9
10
/**
11
 * Class TextField
12
 *
13
 * @author    de Cramer Oliver<[email protected]>
14
 * @copyright 2018 eXpansion
15
 * @package eXpansion\Framework\Config\Ui
16
 */
17
class BooleanField implements UiInterface
18
{
19
    /** @var Factory */
20
    protected $uiFactory;
21
22
    /**
23
     * TextField constructor.
24
     *
25
     * @param Factory $uiFactory
26
     */
27
    public function __construct(Factory $uiFactory)
28
    {
29
        $this->uiFactory = $uiFactory;
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function build(ConfigInterface $config, $width): Renderable
36
    {
37
38
        if ($config->get()) {
39
            $selectedIndex = 0;
40
        } else {
41
            $selectedIndex = 1;
42
        }
43
44
        return $this
45
            ->uiFactory
46
            ->createDropdown($config->getPath(), ["True" => "true", "False" => "false"], $selectedIndex, false)
47
            ->setWidth($width);
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function isCompatible(ConfigInterface $config): bool
54
    {
55
        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...
56
    }
57
}
58