Completed
Push — master ( 3582ec...074093 )
by De Cramer
10s
created

Factory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __call() 0 18 4
1
<?php
2
3
namespace eXpansion\Framework\Gui\Ui;
4
5
use eXpansion\Framework\Core\Exceptions\UnknownMethodException;
6
use eXpansion\Framework\Core\Model\Gui\Factory\BackGroundFactory;
7
use eXpansion\Framework\Gui\Builders\WidgetBackground;
8
use eXpansion\Framework\Gui\Builders\WidgetLabel;
9
use eXpansion\Framework\Gui\Components\Animation;
10
use eXpansion\Framework\Gui\Components\Button;
11
use eXpansion\Framework\Gui\Components\Checkbox;
12
use eXpansion\Framework\Gui\Components\ConfirmButton;
13
use eXpansion\Framework\Gui\Components\Dropdown;
14
use eXpansion\Framework\Gui\Components\Input;
15
use eXpansion\Framework\Gui\Components\InputMasked;
16
use eXpansion\Framework\Gui\Components\Label;
17
use eXpansion\Framework\Gui\Components\Line;
18
use eXpansion\Framework\Gui\Components\Textbox;
19
use eXpansion\Framework\Gui\Components\Tooltip;
20
use eXpansion\Framework\Gui\Layouts\LayoutLine;
21
use eXpansion\Framework\Gui\Layouts\LayoutRow;
22
use eXpansion\Framework\Gui\Layouts\LayoutScrollable;
23
24
/**
25
 * Class Factory
26
 *
27
 * @author    de Cramer Oliver<[email protected]>
28
 * @copyright 2017 eXpansion
29
 * @package eXpansion\Framework\Gui\Ui
30
 *
31
 * @method Button createButton($text, $type = Button::TYPE_DEFAULT)
32
 * @method ConfirmButton createConfirmButton($text, $type = Button::TYPE_DEFAULT)
33
 * @method Checkbox createCheckbox($text, $name, $checked = false, $disabled = false)
34
 * @method Dropdown createDropdown($name, $options, $selectedIndex = -1, $isOpened = false)
35
 * @method Input createInput($name, $default = "", $width = 30)
36
 * @method InputMasked createInputMasked($name, $default = "", $width = 30)
37
 * @method Label createLabel($text = "", $type = Label::TYPE_NORMAL, $controlId = null)
38
 * @method Line createLine($x, $y)
39
 * @method Textbox createTextbox($name, $default = "", $lines = 1, $width = 30)
40
 * @method Tooltip createTooltip()
41
 * @method Animation createAnimation()
42
 *
43
 * @method LayoutLine createLayoutLine($startX, $startY, $elements = [], $margin = 0.);
44
 * @method LayoutRow createLayoutRow($startX, $startY, $elements = [], $margin = 0.);
45
 * @method LayoutScrollable createLayoutScrollable($frame, $sizeX, $sizeY);
46
 *
47
 * @method WidgetBackground createWidgetBackground($width, $height);
48
 * @method WidgetLabel createWidgetLabel($text = "", $type = Label::TYPE_NORMAL, $controlId = null);
49
 */
50
class Factory
51
{
52
    /**
53
     * @var string[]
54
     */
55
    protected $classes;
56
57
    /**
58
     * @var BackGroundFactory[]
59
     */
60
    protected $factories;
61
62
    /**
63
     * Factory constructor.
64
     *
65
     * @param $classes
66
     * @param $factories
67
     */
68 9
    public function __construct($classes, $factories = null)
69
    {
70 9
        $this->classes = $classes;
71 9
        $this->factories = $factories;
72 9
    }
73
74
    /**
75
     * @param $name
76
     * @param $arguments
77
     *
78
     * @return mixed
79
     *
80
     * @throws UnknownMethodException
81
     */
82 9
    public function __call($name, $arguments)
83
    {
84 9
        if (strpos($name, 'create') === 0) {
85 8
            $name = str_replace('create', '', $name);
86
87 8
            if (isset($this->classes[$name])) {
88 7
                $class = $this->classes[$name];
89
90 7
                return new $class(...$arguments);
91
            }
92
93 1
            if (isset($this->factories[$name])) {
94
                return $this->factories[$name]->create(...$arguments);
95
            }
96
        }
97
98 2
        throw new UnknownMethodException("$name is an unknown method");
99
    }
100
}
101