Completed
Branch master (88d491)
by Michael
03:04 queued 01:04
created

GbookEntriesHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * ****************************************************************************
4
 *  GBOOK - MODULE FOR XOOPS
5
 *  Copyright (c) 2007 - 2012
6
 *  Ingo H. de Boer (http://www.winshell.org)
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  (at your option) any later version.
12
 *
13
 *  You may not change or alter any portion of this comment or credits
14
 *  of supporting developers from this source code or any supporting
15
 *  source code which is considered copyrighted (c) material of the
16
 *  original comment or credit authors.
17
 *
18
 *  This program is distributed in the hope that it will be useful,
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 *  GNU General Public License for more details.
22
 *  ---------------------------------------------------------------------------
23
 *
24
 * @copyright       Ingo H. de Boer (http://www.winshell.org)
25
 * @license         GNU General Public License (GPL)
26
 * @package         GBook
27
 * @author          Ingo H. de Boer ([email protected])
28
 *
29
 * ****************************************************************************
30
 */
31
32
/**
33
 * @package   kernel
34
 * @copyright copyright &copy; 2000 XOOPS.org
35
 */
36
class GbookEntries 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...
37
{
38
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        $this->initVar('id', XOBJ_DTYPE_INT, null, true);
45
        $this->initVar('name', XOBJ_DTYPE_TXTBOX);
46
        $this->initVar('email', XOBJ_DTYPE_TXTBOX);
47
        $this->initVar('url', XOBJ_DTYPE_TXTBOX);
48
        $this->initVar('message', XOBJ_DTYPE_OTHER);
49
        $this->initVar('note', XOBJ_DTYPE_OTHER);
50
        $this->initVar('time', XOBJ_DTYPE_INT);
51
        $this->initVar('date', XOBJ_DTYPE_TXTBOX);
52
        $this->initVar('ip', XOBJ_DTYPE_TXTBOX);
53
        $this->initVar('admin', XOBJ_DTYPE_TXTBOX);
54
55
        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false);
56
        $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1, false);
57
        $this->initVar('doxcode', XOBJ_DTYPE_INT, 1, false);
58
        $this->initVar('doimage', XOBJ_DTYPE_INT, 1, false);
59
        $this->initVar('dobr', XOBJ_DTYPE_INT, 1, false);
60
    }
61
62
    /**
63
     * Get {@link XoopsThemeForm} for adding/editing categories
64
     *
65
     * @param mixed $action URL to submit to or false for $_SERVER['REQUEST_URI']
66
     *
67
     * @return XoopsThemeForm
68
     */
69
    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...
70
    {
71
        if ($action === false) {
72
            $action = $_SERVER['REQUEST_URI'];
73
        }
74
        $title = _GBOOK_AM_ENTRY_EDIT;
75
76
        include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
77
        include_once dirname(__DIR__) . '/class/utilities.php';
78
79
        $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
80
81
        $form->addElement(new XoopsFormText(_GBOOK_AM_NAME, 'name', 35, 255, $this->getVar('name')));
82
        $form->addElement(new XoopsFormText(_GBOOK_AM_EMAIL, 'email', 35, 255, $this->getVar('email')));
83
        $form->addElement(new XoopsFormText(_GBOOK_AM_URL, 'url', 35, 255, $this->getVar('url')));
84
85
        $messageEditor = GBookUtilities::getEditor('message', $this->getVar('message', 'e'));
86
        //        $form->addElement(new XoopsFormTextArea(_GBOOK_AM_MESSAGE, 'message', $this->getVar('message', '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...
87
        $form->addElement($messageEditor);
88
89
        $noteEditor = GBookUtilities::getEditor('note', $this->getVar('note', 'e'));
90
        //        $form->addElement(new XoopsFormTextArea(_GBOOK_AM_NOTE, 'note', $this->getVar('note', '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...
91
        $form->addElement($noteEditor);
92
93
        $form->addElement(new XoopsFormHidden('op', 'save'));
94
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
95
96
        return $form;
97
    }
98
}
99
100
/**
101
 * @package   kernel
102
 * @copyright copyright &copy; 2000 XOOPS.org
103
 */
104
class GbookEntriesHandler 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...
105
{
106
    /**
107
     * @param null|XoopsDatabase $db
108
     */
109
    public function __construct(XoopsDatabase $db)
110
    {
111
        parent::__construct($db, 'gbook_entries', 'gbookEntries', 'id', 'name', 'email', 'url', 'message', 'note', 'time', 'date', 'ip', 'admin');
112
    }
113
}
114