Completed
Pull Request — master (#233)
by De Cramer
10:00
created

TextField::build()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 2
1
<?php
2
3
namespace eXpansion\Framework\Config\Ui\Fields;
4
5
use eXpansion\Framework\Config\Model\AbstractConfig;
6
use eXpansion\Framework\Config\Model\ConfigInterface;
7
use eXpansion\Framework\Gui\Ui\Factory;
8
use FML\Controls\Frame;
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 TextField 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): Frame
36
    {
37
        $frame = new Frame();
38
39
        $descriptionButton = $this->uiFactory->createButton("?");
40
        $rowLayout =  $this->uiFactory->createLayoutLine(
41
            0,
42
            0,
43
            [
44
                $this->uiFactory->createLabel($config->getName(), ($width * 2) / 3),
45
                $this->uiFactory->createInput($config->getPath(), ($width * 2) / 3)->setDefault($config->getRawValue()),
46
                $descriptionButton,
47
            ]
48
        );
49
50
        $frame->addChild($rowLayout);
51
        $frame->setSize($width, $rowLayout->getHeight());
52
53
        $tooltip = $this->uiFactory->createTooltip();
54
        $frame->addChild($tooltip);
55
56
        $tooltip->addTooltip($descriptionButton, $config->getDescription());
57
        return $frame;
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function isCompatible(ConfigInterface $config): bool
64
    {
65
        return ($config instanceof AbstractConfig);
0 ignored issues
show
Bug introduced by
The class eXpansion\Framework\Config\Model\AbstractConfig 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...
66
    }
67
}
68