SmartFormRadioElement   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 64.15 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 34
loc 53
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 34 45 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace XoopsModules\Smartobject\Form\Elements;
2
3
/**
4
 * Contains the SmartObjectControl class
5
 *
6
 * @license    GNU
7
 * @author     marcan <[email protected]>
8
 * @link       http://smartfactory.ca The SmartFactory
9
 * @package    SmartObject
10
 * @subpackage SmartObjectForm
11
 */
12
13
use XoopsModules\Smartobject;
14
15
/**
16
 * Class SmartFormRadioElement
17
 * @package XoopsModules\Smartobject\Form\Elements
18
 */
19
class SmartFormRadioElement extends \XoopsFormRadio
20
{
21
    /**
22
     * SmartFormRadioElement constructor.
23
     * @param string $object
24
     * @param string $key
25
     */
26
    public function __construct($object, $key)
27
    {
28
        $var = $object->vars[$key];
29
30
        parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e'));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $object (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
31
32
        // Adding the options inside this SelectBox
33
        // If the custom method is not from a module, than it's from the core
34
        $control = $object->getControl($key);
0 ignored issues
show
Bug introduced by
The method getControl cannot be called on $object (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
35
36 View Code Duplication
        if (isset($control['options'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
            $this->addOptionArray($control['options']);
38
        } else {
39
            // let's find if the method we need to call comes from an already defined object
40
            if (isset($control['object'])) {
41
                if (method_exists($control['object'], $control['method'])) {
42
                    if ($option_array = $control['object']->{$control['method']}()) {
43
                        // Adding the options array to the XoopsFormSelect
44
                        $this->addOptionArray($option_array);
45
                    }
46
                }
47
            } else {
48
                // finding the itemHandler; if none, let's take the itemHandler of the $object
49
                if (isset($control['itemHandler'])) {
50
                    if (!$control['module']) {
51
                        // Creating the specified core object handler
52
                        $controlHandler = xoops_getHandler($control['itemHandler']);
53
                    } else {
54
                        $controlHandler = xoops_getModuleHandler($control['itemHandler'], $control['module']);
55
                    }
56
                } else {
57
                    $controlHandler = $object->handler;
58
                }
59
60
                // Checking if the specified method exists
61
                if (method_exists($controlHandler, $control['method'])) {
62
                    // TODO: How could I pass the parameters in the following call ...
63
                    if ($option_array = $controlHandler->{$control['method']}()) {
64
                        // Adding the options array to the XoopsFormSelect
65
                        $this->addOptionArray($option_array);
66
                    }
67
                }
68
            }
69
        }
70
    }
71
}
72