Completed
Push — master ( 54d4eb...375a6b )
by Michael
02:05
created

RandomquoteQuotesHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 10
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
1
<?php
2
/**
3
 * Module: RandomQuote
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 *
9
 * PHP version 5
10
 *
11
 * @category        Module
12
 * @package         Randomquote
13
 * @author          XOOPS Development Team, Mamba
14
 * @copyright       2001-2016 XOOPS Project (http://xoops.org)
15
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @link            http://xoops.org/
17
 * @since           2.0.0
18
 */
19
20
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
21
22
/**
23
 * Class RandomquoteQuotes
24
 */
25
class RandomquoteQuotes extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
26
{
27
    //Constructor
28
    /**
29
     *
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
        $this->initVar('id', XOBJ_DTYPE_INT, null, false, 11);
35
        $this->initVar('quote', XOBJ_DTYPE_TXTAREA, null, false);
36
        $this->initVar('author', XOBJ_DTYPE_TXTAREA, null, false);
37
        $this->initVar('quote_status', XOBJ_DTYPE_INT, null, false, 10);
38
        $this->initVar('quote_waiting', XOBJ_DTYPE_INT, null, false, 10);
39
        $this->initVar('quote_online', XOBJ_DTYPE_INT, null, false, 1);
40
41
        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false);
42
        $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1, false);
43
        $this->initVar('doxcode', XOBJ_DTYPE_INT, 1, false);
44
        $this->initVar('doimage', XOBJ_DTYPE_INT, 1, false);
45
        $this->initVar('dobr', XOBJ_DTYPE_INT, 1, false);
46
    }
47
48
    /**
49
     * @param bool $action
50
     *
51
     * @return XoopsThemeForm
52
     */
53
    public function getForm($action = false)
0 ignored issues
show
Coding Style introduced by
getForm uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
getForm uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
54
    {
55
        // global $xoopsDB, $xoopsModuleConfig;
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...
56
57
        if ($action === false) {
58
            $action = $_SERVER['REQUEST_URI'];
59
        }
60
61
        $title = $this->isNew() ? sprintf(_AM_RANDOMQUOTE_QUOTES_ADD) : sprintf(_AM_RANDOMQUOTE_QUOTES_EDIT);
62
63
        include_once(XOOPS_ROOT_PATH . '/class/xoopsformloader.php');
64
65
        $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
66
        $form->setExtra('enctype="multipart/form-data"');
67
68
        $author     = $this->isNew() ? '' : $this->getVar('author');
69
        $textAuthor = new XoopsFormText(_AM_RANDOMQUOTE_QUOTES_AUTHOR, 'author', 50, 255, $author);
70
        $form->addElement($textAuthor);
71
72
        $editorConfigs           = array();
73
        $editorConfigs['name']   = 'quote';
74
        $editorConfigs['value']  = $this->getVar('quote', 'e');
75
        $editorConfigs['rows']   = 10;
76
        $editorConfigs['cols']   = 80;
77
        $editorConfigs['width']  = '100%';
78
        $editorConfigs['height'] = '400px';
79
        $editorConfigs['editor'] = $GLOBALS['xoopsModuleConfig']['randomquote_editor'];
80
        $form->addElement(new XoopsFormEditor(_AM_RANDOMQUOTE_QUOTES_QUOTE, 'quote', $editorConfigs), true);
81
82
        //        $editorConfigs           = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
83
        //        $editorConfigs["name"]   = "author";
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
84
        //        $editorConfigs["value"]  = $this->getVar("author", "e");
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...
85
        //        $editorConfigs["rows"]   = 10;
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
86
        //        $editorConfigs["cols"]   = 80;
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
87
        //        $editorConfigs["width"]  = "100%";
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
88
        //        $editorConfigs["height"] = "400px";
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
89
        //        $editorConfigs["editor"] = $GLOBALS["xoopsModuleConfig"]["randomquote_editor"];
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...
90
        //        $form->addElement(new XoopsFormEditor(_AM_RANDOMQUOTE_QUOTES_AUTHOR, "author", $editorConfigs), true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
91
92
        $quote_status       = $this->isNew() ? 0 : $this->getVar('quote_status');
93
        $check_quote_status = new XoopsFormCheckBox(_AM_RANDOMQUOTE_QUOTES_STATUS, 'quote_status', $quote_status);
94
        $check_quote_status->addOption(1, ' ');
95
        $form->addElement($check_quote_status);
96
        $quote_waiting       = $this->isNew() ? 0 : $this->getVar('quote_waiting');
97
        $check_quote_waiting = new XoopsFormCheckBox(_AM_RANDOMQUOTE_QUOTES_WAITING, 'quote_waiting', $quote_waiting);
98
        $check_quote_waiting->addOption(1, ' ');
99
        $form->addElement($check_quote_waiting);
100
        $quote_online       = $this->isNew() ? 0 : $this->getVar('quote_online');
101
        $check_quote_online = new XoopsFormCheckBox(_AM_RANDOMQUOTE_QUOTES_ONLINE, 'quote_online', $quote_online);
102
        $check_quote_online->addOption(1, ' ');
103
        $form->addElement($check_quote_online);
104
105
        $form->addElement(new XoopsFormHidden('op', 'save_quote'));
106
107
        //Submit buttons
108
        $button_tray   = new XoopsFormElementTray('', '');
109
        $submit_button = new XoopsFormButton('', 'submit', _SUBMIT, 'submit');
110
        $button_tray->addElement($submit_button);
111
112
        $cancel_button = new XoopsFormButton('', '', _CANCEL, 'cancel');
113
        $cancel_button->setExtra('onclick="history.go(-1)"');
114
        $button_tray->addElement($cancel_button);
115
116
        $form->addElement($button_tray);
117
118
        return $form;
119
    }
120
}
121
122
/**
123
 * Class RandomquoteQuotesHandler
124
 */
125
class RandomquoteQuotesHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
126
{
127
    /**
128
     * @param null|XoopsDatabase $db
129
     */
130
    public function __construct(XoopsDatabase $db)
131
    {
132
        parent::__construct($db, 'randomquote_quotes', 'RandomquoteQuotes', 'id', 'quote');
133
    }
134
}
135