Completed
Pull Request — master (#3)
by
unknown
01:52
created

XsitemapPluginHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 29.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 * ****************************************************************************
4
 * Module generated by TDMCreate from TDM "http://www.tdmxoops.net"
5
 * ****************************************************************************
6
 * xsitemap - MODULE FOR XOOPS CMS
7
 * Copyright (c) Urbanspaceman (http://www.takeaweb.it)
8
 *
9
 * You may not change or alter any portion of this comment or credits
10
 * of supporting developers from this source code or any supporting source code
11
 * which is considered copyrighted (c) material of the original comment or credit authors.
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
/**
17
 * Module: xsitemap
18
 *
19
 * @package    module\xsitemap\class
20
 * @author     XOOPS Module Development Team
21
 * @author     http://www.takeaweb.it Urbanspaceman
22
 * @copyright  http://www.takeaweb.it Urbanspaceman
23
 * @copyright  http://xoops.org 2001-2017 XOOPS Project
24
 * @license    http://www.fsf.org/copyleft/gpl.html GNU public license
25
 * @link       http://xoops.org XOOPS
26
 * @since      1.00
27
 */
28
29
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
30
31
class XsitemapPlugin 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...
32
{
33
        //Constructor
34
        public function __construct()
35
        {
36
            parent::__construct();
37
            $this->initVar('plugin_id', XOBJ_DTYPE_INT, null, false, 8);
38
            $this->initVar('plugin_name', XOBJ_DTYPE_TXTBOX, null, false);
39
            $this->initVar('plugin_mod_version', XOBJ_DTYPE_TXTBOX, null, false);
40
            $this->initVar('plugin_mod_table', XOBJ_DTYPE_TXTBOX, null, false);
41
            $this->initVar('plugin_cat_id', XOBJ_DTYPE_TXTBOX, null, false);
42
            $this->initVar('plugin_cat_pid', XOBJ_DTYPE_TXTBOX, null, false);
43
            $this->initVar('plugin_cat_name', XOBJ_DTYPE_TXTBOX, null, false);
44
            $this->initVar('plugin_weight', XOBJ_DTYPE_TXTBOX, null, false);
45
            $this->initVar('plugin_call', XOBJ_DTYPE_TXTBOX, null, false);
46
            $this->initVar('plugin_submitter', XOBJ_DTYPE_INT, null, false, 10);
47
            $this->initVar('plugin_date_created', XOBJ_DTYPE_INT, null, false, 10);
48
            $this->initVar('plugin_online', XOBJ_DTYPE_INT, null, false, 1);
49
50
            // to allow html
51
            $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false);
52
53
        }
54
55
        public function __toString() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
56
            return $this->getVar('plugin_name', 's');
57
        }
58
59
        public function getForm($action = false)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
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...
60
        {
61
            global $xoopsDB, $xoopsModuleConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
62
63
            if (false === $action) {
64
                $action = $_SERVER["REQUEST_URI"];
65
            }
66
67
            if ($this->isNew()) {
68
                $title = _AM_XSITEMAP_PLUGIN_ADD;
69
                $plugin_date_created = time();
70
                $plugin_online = 1;
71
            } else {
72
                $title = _AM_XSITEMAP_PLUGIN_EDIT;
73
                $plugin_date_created = $this->getVar("plugin_date_created");
74
                $plugin_online = $this->getVar("plugin_online");
75
            }
76
//            $title = $this->isNew() ? sprintf(_AM_XSITEMAP_PLUGIN_ADD) : sprintf(_AM_XSITEMAP_PLUGIN_EDIT);
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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...
77
78
            include_once $GLOBALS['xoops']->path("class/xoopsformloader.php");
79
80
            $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
81
            $form->setExtra('enctype="multipart/form-data"');
82
83
            $form->addElement(new XoopsFormText(_AM_XSITEMAP_PLUGIN_NAME, "plugin_name", 50, 255, $this->getVar("plugin_name")), true);
84
            $form->addElement(new XoopsFormText(_AM_XSITEMAP_PLUGIN_MOD_VERSION, "plugin_mod_version", 50, 255, $this->getVar("plugin_mod_version")), true);
85
            $form->addElement(new XoopsFormText(_AM_XSITEMAP_PLUGIN_MOD_TABLE, "plugin_mod_table", 50, 255, $this->getVar("plugin_mod_table")), true);
86
            $form->addElement(new XoopsFormText(_AM_XSITEMAP_PLUGIN_CAT_ID, "plugin_cat_id", 50, 255, $this->getVar("plugin_cat_id")), true);
87
            $form->addElement(new XoopsFormText(_AM_XSITEMAP_PLUGIN_CAT_PID, "plugin_cat_pid", 50, 255, $this->getVar("plugin_cat_pid")), true);
88
            $form->addElement(new XoopsFormText(_AM_XSITEMAP_PLUGIN_CAT_NAME, "plugin_cat_name", 50, 255, $this->getVar("plugin_cat_name")), true);
89
            $form->addElement(new XoopsFormText(_AM_XSITEMAP_PLUGIN_WEIGHT, "plugin_weight", 50, 255, $this->getVar("plugin_weight")), true);
90
            $form->addElement(new XoopsFormText(_AM_XSITEMAP_PLUGIN_CALL, "plugin_call", 50, 255, $this->getVar("plugin_call")), true);
91
            $form->addElement(new XoopsFormSelectUser(_AM_XSITEMAP_PLUGIN_SUBMITTER, "plugin_submitter", false, $this->getVar("plugin_submitter"), 1, false), true);
92
//            $plugin_date_created = $this->isNew() ? time() : $this->getVar("plugin_date_created");
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
93
            $form->addElement(new XoopsFormTextDateSelect(_AM_XSITEMAP_PLUGIN_DATE_CREATED, "plugin_date_created", "", $plugin_date_created));
94
//            $plugin_online = $this->isNew() ? 1 : $this->getVar("plugin_online");
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
95
            $check_plugin_online = new XoopsFormCheckBox(_AM_XSITEMAP_PLUGIN_ONLINE, "plugin_online", $plugin_online);
96
            $check_plugin_online->addOption(1, " ");
97
            $form->addElement($check_plugin_online);
98
            $form->addElement(new XoopsFormHidden("op", "save_plugin"));
99
            if (!$this->isNew()) {
100
                $form->addElement(new XoopsFormHidden("plugin_id", $this->getVar('plugin_id')));
101
            }
102
            $form->addElement(new XoopsFormButtonTray('submit', _SUBMIT));
103
104
            return $form->display();
105
        }
106
    }
107
    class XsitemapPluginHandler 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...
108
    {
109
110
        public function __construct(&$db)
111
        {
112
            parent::__construct($db, "xsitemap_plugin", "XsitemapPlugin", "plugin_id", "plugin_name");
113
        }
114
    }
115