Completed
Push — master ( 5e0a7d...23f988 )
by De Cramer
03:04
created

Factory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 50
rs 10
ccs 13
cts 13
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __call() 0 17 4
1
<?php
2
3
namespace eXpansion\Framework\Gui\Ui;
4
5
use eXpansion\Framework\Core\Model\Gui\Factory\BackGroundFactory;
6
use eXpansion\Framework\Gui\Components\UiButton;
7
use eXpansion\Framework\Gui\Components\uiCheckbox;
8
use eXpansion\Framework\Gui\Components\uiDropdown;
9
use eXpansion\Framework\Gui\Components\uiInput;
10
use eXpansion\Framework\Gui\Components\uiLabel;
11
use eXpansion\Framework\Gui\Components\uiLine;
12
use eXpansion\Framework\Gui\Components\uiTextbox;
13
use eXpansion\Framework\Gui\Components\uiTooltip;
14
use eXpansion\Framework\Gui\Layouts\layoutLine;
15
use eXpansion\Framework\Gui\Layouts\layoutRow;
16
17
use eXpansion\Framework\Core\Exceptions\UnknownMethodException;
18
use FML\Controls\Frame;
19
20
/**
21
 * Class Factory
22
 *
23
 * @author    de Cramer Oliver<[email protected]>
24
 * @copyright 2017 Smile
25
 * @package eXpansion\Framework\Gui\Ui
26
 *
27
 * @method UiButton createButton($text, $type = UiButton::TYPE_DEFAULT)
28
 * @method uiCheckbox createCheckbox($text, $name, $checked = false, $disabled = false)
29
 * @method uiDropdown createDropdown($name, $options, $selectedIndex = -1, $isOpened = false)
30
 * @method uiInput createInput($name, $default = "", $width = 30)
31
 * @method uiLabel createLabel($text = "", $type = uiLabel::TYPE_NORMAL, $controlId = null)
32
 * @method uiLine createLine($x, $y)
33
 * @method uiTextbox createTextbox($name, $default = "", $lines = 1, $width = 30)
34
 * @method uiTooltip createTooltip()
35
 *
36
 * @method layoutLine createLayoutLine($startX, $startY, $elements = [], $margin = 0.);
37
 * @method layoutRow createLayoutRow($startX, $startY, $elements = [], $margin = 0.);
38
 *
39
 * @method Frame createBackground($width, $height, $index = 0)
40
 * @method Frame createTitleBackground($width, $height, $index = 0)
41
 * @method Frame createPager($width, $currentPageNumber, $lastPageNumber, $actionFirstPage, $actionPreviousPage, $actionNextPage, $actionLastPage)
42
 * @method Frame createGridLine($totalWidth, $columns, $index = 0, $height = 5.0, $autoNewLine = false, $maxLines = 1)
43
 */
44
class Factory
45
{
46
    /**
47
     * @var string[]
48
     */
49
    protected $classes;
50
51
    /**
52
     * @var BackGroundFactory[]
53
     */
54
    protected $factories;
55
56
    /**
57
     * Factory constructor.
58
     *
59
     * @param $classes
60
     * @param $factories
61
     */
62 3
    public function __construct($classes, $factories)
63
    {
64 3
        $this->classes = $classes;
65 3
        $this->factories = $factories;
66 3
    }
67
68
    /**
69
     * @param $name
70
     * @param $arguments
71
     *
72
     * @return mixed
73
     *
74
     * @throws UnknownMethodException
75
     */
76 3
    public function __call($name, $arguments)
77
    {
78 3
        if (strpos($name, 'create') === 0) {
79 2
            $name = str_replace('create', '', $name);
80
81 2
            if (isset($this->classes[$name])) {
82 1
                $class = $this->classes[$name];
83 1
                return new $class(...$arguments);
84
            }
85
86 2
            if (isset($this->factories[$name])) {
87 1
                return $this->factories[$name]->create(...$arguments);
1 ignored issue
show
Bug introduced by
The call to create() misses a required argument $height.

This check looks for function calls that miss required arguments.

Loading history...
88
            }
89
        }
90
91 2
        throw new UnknownMethodException("$name is an unknown method");
92
    }
93
}
94