Completed
Push — master ( 01b1a5...81f493 )
by Michael
04:03
created

adsense.php ➔ editclass()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 29
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 24
c 1
b 0
f 0
nc 10
nop 3
dl 0
loc 29
rs 6.7272
1
<?php
2
3
/**
4
 *
5
 * Module: Class_Booking
6
 * Author: The SmartFactory <www.smartfactory.ca>
7
 * Licence: GNU
8
 * @param bool $showmenu
9
 * @param int  $adsenseid
10
 * @param bool $clone
11
 */
12
13
function editclass($showmenu = false, $adsenseid = 0, $clone = false)
14
{
15
    global $smartobjectAdsenseHandler;
16
17
    $adsenseObj = $smartobjectAdsenseHandler->get($adsenseid);
18
19
    if (!$clone && !$adsenseObj->isNew()) {
20
        if ($showmenu) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
21
            //smart_adminMenu(3, _AM_SOBJECT_ADSENSES . " > " . _AM_SOBJECT_EDITING);
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
22
        }
23
        smart_collapsableBar('adsenseedit', _AM_SOBJECT_ADSENSES_EDIT, _AM_SOBJECT_ADSENSES_EDIT_INFO);
24
25
        $sform = $adsenseObj->getForm(_AM_SOBJECT_ADSENSES_EDIT, 'addadsense');
26
        $sform->display();
27
        smart_close_collapsable('adsenseedit');
28
    } else {
29
        $adsenseObj->setVar('adsenseid', 0);
30
        $adsenseObj->setVar('tag', '');
31
32
        if ($showmenu) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
33
            //smart_adminMenu(3, _AM_SOBJECT_ADSENSES . " > " . _CO_SOBJECT_CREATINGNEW);
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
34
        }
35
36
        smart_collapsableBar('adsensecreate', _AM_SOBJECT_ADSENSES_CREATE, _AM_SOBJECT_ADSENSES_CREATE_INFO);
37
        $sform = $adsenseObj->getForm(_AM_SOBJECT_ADSENSES_CREATE, 'addadsense', false, false, false, true);
38
        $sform->display();
39
        smart_close_collapsable('adsensecreate');
40
    }
41
}
42
43
include_once __DIR__ . '/admin_header.php';
44
include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
45
include_once SMARTOBJECT_ROOT_PATH . 'class/adsense.php';
46
$smartobjectAdsenseHandler = xoops_getModuleHandler('adsense');
47
smart_loadLanguageFile('smartobject', 'adsense');
48
$indexAdmin = new ModuleAdmin();
49
50
$op = '';
51
52
if (isset($_GET['op'])) {
53
    $op = $_GET['op'];
54
}
55
if (isset($_POST['op'])) {
56
    $op = $_POST['op'];
57
}
58
59
switch ($op) {
60 View Code Duplication
    case 'mod':
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...
61
62
        $adsenseid = isset($_GET['adsenseid']) ? (int)$_GET['adsenseid'] : 0;
63
64
        smart_xoops_cp_header();
65
        echo $indexAdmin->addNavigation(basename(__FILE__));
66
67
        editclass(true, $adsenseid);
68
        break;
69
70 View Code Duplication
    case 'clone':
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...
71
72
        $adsenseid = isset($_GET['adsenseid']) ? (int)$_GET['adsenseid'] : 0;
73
74
        smart_xoops_cp_header();
75
        echo $indexAdmin->addNavigation(basename(__FILE__));
76
77
        editclass(true, $adsenseid, true);
78
        break;
79
80
    case 'addadsense':
81
        if (@include_once SMARTOBJECT_ROOT_PATH . 'include/captcha/captcha.php') {
82
            $xoopsCaptcha = XoopsCaptcha::getInstance();
83
            if (!$xoopsCaptcha->verify()) {
84
                redirect_header('javascript:history.go(-1);', 3, $xoopsCaptcha->getMessage());
85
                exit;
86
            }
87
        }
88
        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
89
        $controller = new SmartObjectController($smartobjectAdsenseHandler);
90
        $controller->storeFromDefaultForm(_AM_SOBJECT_ADSENSES_CREATED, _AM_SOBJECT_ADSENSES_MODIFIED);
91
        break;
92
93
    case 'del':
94
95
        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
96
        $controller = new SmartObjectController($smartobjectAdsenseHandler);
97
        $controller->handleObjectDeletion();
98
99
        break;
100
101
    default:
102
103
        smart_xoops_cp_header();
104
        echo $indexAdmin->addNavigation(basename(__FILE__));
105
106
        //smart_adminMenu(3, _AM_SOBJECT_ADSENSES);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
107
108
        smart_collapsableBar('createdadsenses', _AM_SOBJECT_ADSENSES, _AM_SOBJECT_ADSENSES_DSC);
109
110
        include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
111
        $objectTable = new SmartObjectTable($smartobjectAdsenseHandler);
112
        $objectTable->addColumn(new SmartObjectColumn('description', 'left'));
113
        $objectTable->addColumn(new SmartObjectColumn(_AM_SOBJECT_ADSENSE_TAG, 'center', 200, 'getXoopsCode'));
0 ignored issues
show
Documentation introduced by
200 is of type integer, 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...
Documentation introduced by
'getXoopsCode' 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...
114
115
        //      $objectTable->addCustomAction('getCreateItemLink');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
116
        //      $objectTable->addCustomAction('getCreateAttributLink');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
117
118
        $objectTable->addIntroButton('addadsense', 'adsense.php?op=mod', _AM_SOBJECT_ADSENSES_CREATE);
119
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
120
                $criteria_upcoming = new CriteriaCompo();
121
                $criteria_upcoming->add(new Criteria('start_date', time(), '>'));
122
                $objectTable->addFilter(_AM_SOBJECT_FILTER_UPCOMING, array(
123
                                            'key' => 'start_date',
124
                                            'criteria' => $criteria_upcoming
125
                ));
126
127
                $criteria_last7days = new CriteriaCompo();
128
                $criteria_last7days->add(new Criteria('start_date', time() - 30 *(60 * 60 * 24), '>'));
129
                $criteria_last7days->add(new Criteria('start_date', time(), '<'));
130
                $objectTable->addFilter(_AM_SOBJECT_FILTER_LAST7DAYS, array(
131
                                            'key' => 'start_date',
132
                                            'criteria' => $criteria_last7days
133
                ));
134
135
                $criteria_last30days = new CriteriaCompo();
136
                $criteria_last30days->add(new Criteria('start_date', time() - 30 *(60 * 60 * 24), '>'));
137
                $criteria_last30days->add(new Criteria('start_date', time(), '<'));
138
                $objectTable->addFilter(_AM_SOBJECT_FILTER_LAST30DAYS, array(
139
                                            'key' => 'start_date',
140
                                            'criteria' => $criteria_last30days
141
                ));
142
        */
143
        $objectTable->addQuickSearch(array('title', 'summary', 'description'));
144
        $objectTable->addCustomAction('getCloneLink');
145
146
        $objectTable->render();
147
148
        echo '<br>';
149
        smart_close_collapsable('createdadsenses');
150
        echo '<br>';
151
152
        break;
153
}
154
155
//smart_modFooter();
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
156
//xoops_cp_footer();
157
include_once __DIR__ . '/admin_footer.php';
158