tag.php ➔ edittag()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 3
dl 0
loc 42
rs 9.248
c 0
b 0
f 0
1
<?php
2
3
use XoopsModules\Smartobject;
4
use XoopsModules\Smartobject\ObjectColumn;
5
use XoopsModules\Smartobject\ObjectController;
6
use XoopsModules\Smartobject\Table;
7
8
/**
9
 *
10
 * Module: SmartShop
11
 * Author: The SmartFactory <www.smartfactory.ca>
12
 * Licence: GNU
13
 * @param int  $tagid
14
 * @param bool $language
15
 * @param bool $fct
16
 */
17
18
function edittag($tagid = 0, $language = false, $fct = false)
0 ignored issues
show
Unused Code introduced by
The parameter $fct 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...
19
{
20
    global $smartobjectTagHandler;
21
22
    $tagObj = $smartobjectTagHandler->get($tagid);
23
24
    if ($tagObj->isNew()) {
25
        $breadcrumb            = _AM_SOBJECT_TAGS . ' > ' . _AM_SOBJECT_TAG_CREATE;
0 ignored issues
show
Unused Code introduced by
$breadcrumb is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26
        $title                 = _AM_SOBJECT_TAG_CREATE;
27
        $info                  = _AM_SOBJECT_TAG_CREATE_INFO;
28
        $collaps_name          = 'tagcreate';
29
        $form_name             = _AM_SOBJECT_TAG_CREATE;
30
        $submit_button_caption = null;
31
    //$tagObj->stripMultilanguageFields();
32
    } else {
33
        if ($language) {
34
            $breadcrumb            = _AM_SOBJECT_TAGS . ' > ' . _AM_SOBJECT_TAG_EDITING_LANGUAGE;
0 ignored issues
show
Unused Code introduced by
$breadcrumb is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
            $title                 = _AM_SOBJECT_TAG_EDIT_LANGUAGE;
36
            $info                  = _AM_SOBJECT_TAG_EDIT_LANGUAGE_INFO;
37
            $collaps_name          = 'tageditlanguage';
38
            $form_name             = _AM_SOBJECT_TAG_EDIT_LANGUAGE;
39
            $submit_button_caption = null;
40
            $tagObj->makeNonMLFieldReadOnly();
41
        } else {
42
            $breadcrumb            = _AM_SOBJECT_TAGS . ' > ' . _AM_SOBJECT_EDITING;
0 ignored issues
show
Unused Code introduced by
$breadcrumb is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
            $title                 = _AM_SOBJECT_TAG_EDIT;
44
            $info                  = _AM_SOBJECT_TAG_EDIT_INFO;
45
            $collaps_name          = 'tagedit';
46
            $form_name             = _AM_SOBJECT_TAG_EDIT;
47
            $submit_button_caption = null;
48
            $tagObj->stripMultilanguageFields();
49
        }
50
    }
51
52
    //Smartobject\Utility::getAdminMenu(2, $breadcrumb);
53
54
    Smartobject\Utility::getCollapsableBar($collaps_name, $title, $info);
55
56
    $sform = $tagObj->getForm($form_name, 'addtag', false, $submit_button_caption);
57
    $sform->display();
58
    Smartobject\Utility::closeCollapsable($collaps_name);
59
}
60
61
require_once __DIR__ . '/admin_header.php';
62
//require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
63
//require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttag.php';
64
65
$smartobjectTagHandler = Smartobject\Helper::getInstance()->getHandler('Tag');
66
67
$op = '';
68
69
if (isset($_GET['op'])) {
70
    $op = $_GET['op'];
71
}
72
if (isset($_POST['op'])) {
73
    $op = $_POST['op'];
74
}
75
76
$tagid    = \Xmf\Request::getInt('tagid', 0, 'GET');
77
$fct      = \Xmf\Request::getString('fct', '', 'GET');
78
$language = isset($_GET['language']) ? $_GET['language'] : false;
79
80
switch ($op) {
81
82
    case 'del':
83
//        require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
84
        $controller = new ObjectController($smartobjectTagHandler);
85
        $controller->handleObjectDeletion(_AM_SOBJECT_TAG_DELETE_CONFIRM);
0 ignored issues
show
Documentation introduced by
_AM_SOBJECT_TAG_DELETE_CONFIRM is of type string, but the function expects a boolean.

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...
86
87
        break;
88
89
    case 'addtag':
90
//        require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
91
        $controller = new ObjectController($smartobjectTagHandler);
92
        $tagObj     = $controller->storeSmartObject();
93
        if ($tagObj->hasError()) {
0 ignored issues
show
Bug introduced by
The method hasError cannot be called on $tagObj (of type boolean).

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...
94
            redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $tagObj->getHtmlErrors());
0 ignored issues
show
Bug introduced by
The method getHtmlErrors cannot be called on $tagObj (of type boolean).

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...
95
        }
96
97
        if ($tagObj->hasError()) {
0 ignored issues
show
Bug introduced by
The method hasError cannot be called on $tagObj (of type boolean).

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...
98
            redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $tagObj->getHtmlErrors());
0 ignored issues
show
Bug introduced by
The method getHtmlErrors cannot be called on $tagObj (of type boolean).

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...
99
        } else {
100
            redirect_header(Smartobject\Utility::getPageBeforeForm(), 3, _CO_SOBJECT_SAVE_SUCCESS);
101
        }
102
        exit;
103
        break;
104
105
    case 'mod':
106
        Smartobject\Utility::getXoopsCpHeader();
107
        edittag($tagid, $language, $fct);
108
        break;
109
110
    default:
111
112
        Smartobject\Utility::getXoopsCpHeader();
113
114
        //Smartobject\Utility::getAdminMenu(2, _AM_SOBJECT_TAGS);
115
116
        Smartobject\Utility::getCollapsableBar('tags', _AM_SOBJECT_TAGS, _AM_SOBJECT_TAGS_INFO);
117
118
//        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
119
        $objectTable = new Table($smartobjectTagHandler, false, ['delete']);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a null|object<CriteriaElement>.

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...
120
        $objectTable->addColumn(new ObjectColumn('name'));
121
        $objectTable->addColumn(new ObjectColumn('language'));
122
        $objectTable->addColumn(new ObjectColumn('value'));
123
        //      $objectTable->addColumn(new SmartObjectColumn(_AM_SOBJECT_SENT_TAGS_FROM, $align='left', $width=false, 'getFromInfo'));
124
125
        $objectTable->addFilter('language', 'getLanguages');
126
127
        $objectTable->addCustomAction('getEditLanguageLink');
128
        $objectTable->addCustomAction('getEditItemLink');
129
130
        $objectTable->setDefaultSort('tagid');
131
132
        $objectTable->addIntroButton('addtag', 'tag.php?op=mod', _AM_SOBJECT_TAG_CREATE);
133
134
        $objectTable->render();
135
136
        echo '<br>';
137
        Smartobject\Utility::closeCollapsable('tags');
138
        echo '<br>';
139
140
        break;
141
}
142
143
//Smartobject\Utility::getModFooter();
144
//xoops_cp_footer();
145
require_once __DIR__ . '/admin_footer.php';
146