SmartFormImageElement   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 30 5
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 SmartFormImageElement
17
 * @package XoopsModules\Smartobject\Form\Elements
18
 */
19
class SmartFormImageElement extends \XoopsFormElementTray
20
{
21
    /**
22
     * SmartFormImageElement constructor.
23
     * @param string $object
24
     * @param string $key
25
     */
26
    public function __construct($object, $key)
27
    {
28
        $var             = $object->vars[$key];
29
        $object_imageurl = $object->getImageDir();
0 ignored issues
show
Bug introduced by
The method getImageDir 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...
30
        parent::__construct($var['form_caption'], ' ');
31
32
        $objectArray['image'] = str_replace('{XOOPS_URL}', XOOPS_URL, $objectArray['image']);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$objectArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $objectArray = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The variable $objectArray seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
33
34
        if ('' !== $object->getVar($key)
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...
35
            && (0 === strpos($object->getVar($key), 'http')
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...
36
                || 0 === strpos($object->getVar($key), '{XOOPS_URL}'))) {
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...
37
            $this->addElement(new \XoopsFormLabel('', "<img src='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar($key)) . "' alt=''><br><br>"));
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...
38
        } elseif ('' !== $object->getVar($key)) {
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...
39
            $this->addElement(new \XoopsFormLabel('', "<img src='" . $object_imageurl . $object->getVar($key) . "' alt=''><br><br>"));
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...
40
        }
41
42
//        require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php';
43
        $this->addElement(new SmartFormFileUploadElement($object, $key));
44
45
        $this->addElement(new \XoopsFormLabel('<div style="height: 10px; padding-top: 8px; font-size: 80%;">' . _CO_SOBJECT_URL_FILE_DSC . '</div>', ''));
46
//        require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformtextelement.php';
47
//        require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php';
48
49
        $this->addElement(new \XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE));
50
        $this->addElement(new SmartFormTextElement($object, 'url_' . $key));
51
        $this->addElement(new \XoopsFormLabel('', '<br><br>'));
52
        $delete_check = new SmartFormCheckElement('', 'delete_' . $key);
53
        $delete_check->addOption(1, '<span style="color:red;">' . _CO_SOBJECT_DELETE . '</span>');
54
        $this->addElement($delete_check);
55
    }
56
}
57