Completed
Pull Request — master (#341)
by De Cramer
05:55
created

FmlComponent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
namespace eXpansion\Framework\MlComposeBundle\UiComponents;
4
5
use eXpansion\Framework\Core\Model\Gui\FmlManialink;
6
use eXpansion\Framework\Core\Plugins\Gui\FmlManialinkFactory;
7
use FML\Controls\Control;
8
use FML\Controls\Frame;
9
use oliverde8\AssociativeArraySimplified\AssociativeArray;
10
use Oliverde8\PageCompose\Block\BlockDefinitionInterface;
11
use Oliverde8\PageCompose\Service\UiComponents;
12
use Oliverde8\PageCompose\UiComponent\AbstractUiComponent;
13
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
14
use Symfony\Component\PropertyAccess\PropertyAccess;
15
16
/**
17
 * Class BaseFmlComponent
18
 *
19
 * @author    de Cramer Oliver<[email protected]>
20
 * @copyright 2018 Oliverde8
21
 * @package eXpansion\Framework\MlComposeBundle\UiComponents
22
 */
23
class FmlComponent extends AbstractUiComponent
24
{
25
    public function __construct(UiComponents $uiComponents, $fmlClass)
0 ignored issues
show
Unused Code introduced by
The parameter $fmlClass is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        parent::__construct($uiComponents);
28
        $this->propertAccess = PropertyAccess::createPropertyAccessor();
0 ignored issues
show
Bug introduced by
The property propertAccess does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
    }
30
31
32
    /**
33
     * Display the component.
34
     *
35
     * @param BlockDefinitionInterface $blockDefinition
36
     * @param array ...$args
37
     *
38
     * @return string
39
     */
40
    public function display(BlockDefinitionInterface $blockDefinition, ...$args)
41
    {
42
        $arguments = [
43
            'factory' => $args[0],
44
            'manialink' => $args[1],
45
            'args' => $args,
46
        ];
47
        $expressionLanguage = new ExpressionLanguage();
48
        $configuration = new AssociativeArray($blockDefinition->getConfiguration());
49
        $class = $configuration->get('class');
50
51
        /** @var Control  $component */
52
        $component = new $class($configuration->get('id', $blockDefinition->getUniqueKey()));
53
54
        foreach ($blockDefinition->getSubBlocks() as $block) {
55
            /** @var Frame  $component */
56
            $component->addChild($this->uiComponents->display($block, ...$args));
0 ignored issues
show
Documentation introduced by
$this->uiComponents->display($block, ...$args) is of type null|string, but the function expects a object<FML\Types\Renderable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
        }
58
59
        foreach ($blockDefinition->getConfiguration() as $key => $value) {
60
            $function = ucwords("set_$key");
61
            $component->$function($expressionLanguage->evaluate($value, $arguments));
62
        }
63
64
        return $component;
65
    }
66
}
67