Completed
Push — master ( c8eead...62889a )
by Michael
04:13
created

PedigreeTemp::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
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 30 and the first side effect is on line 24.

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
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * animal module for xoops
13
 *
14
 * @copyright       The TXMod XOOPS Project http://sourceforge.net/projects/thmod/
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GPL 2.0 or later
17
 * @package         animal
18
 * @since           2.5.x
19
 * @author          XOOPS Development Team ( [email protected] ) - ( http://xoops.org )
20
 * @version         $Id: const_entete.php 9860 2012-07-13 10:41:41Z txmodxoops $
21
 */
22
23
if (!defined("XOOPS_ROOT_PATH")) {
24
    die("XOOPS root path not defined");
25
}
26
27
/**
28
 * Class PedigreeTemp
29
 */
30
class PedigreeTemp 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...
31
{
32
    //Constructor
33
    /**
34
     *
35
     */
36
    function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
    {
38
        parent::__construct();
39
        $this->initVar("ID", XOBJ_DTYPE_INT, null, false, 11);
40
        $this->initVar("NAAM", XOBJ_DTYPE_TXTAREA, null, false);
41
        $this->initVar("id_owner", XOBJ_DTYPE_INT, null, false, 11);
42
        $this->initVar("id_breeder", XOBJ_DTYPE_INT, null, false, 11);
43
        $this->initVar("user", XOBJ_DTYPE_TXTBOX, null, false, 25);
44
        $this->initVar("roft", XOBJ_DTYPE_TXTAREA, null, false);
45
        $this->initVar("mother", XOBJ_DTYPE_INT, null, false, 5);
46
        $this->initVar("father", XOBJ_DTYPE_INT, null, false, 5);
47
        $this->initVar("foto", XOBJ_DTYPE_TXTBOX, null, false, 255);
48
        $this->initVar("coi", XOBJ_DTYPE_TXTBOX, null, false, 10);
49
50
    }
51
52
    /**
53
     * @param bool $action
54
     *
55
     * @return XoopsThemeForm
56
     */
57
    function getForm($action = false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

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...
58
    {
59
        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...
60
61
        if ($action === false) {
62
            $action = $_SERVER["REQUEST_URI"];
63
        }
64
65
        $title = $this->isNew() ? sprintf(_AM_PEDIGREE_PEDIGREE_TEMP_ADD) : sprintf(_AM_PEDIGREE_PEDIGREE_TEMP_EDIT);
66
67
        include_once(XOOPS_ROOT_PATH . "/class/xoopsformloader.php");
68
69
        $form = new XoopsThemeForm($title, "form", $action, "post", true);
70
        $form->setExtra('enctype="multipart/form-data"');
71
72
        $form->addElement(new XoopsFormTextArea(_AM_PEDIGREE_PEDIGREE_TEMP_NAAM, "NAAM", $this->getVar("NAAM"), 4, 47), true);
73
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_TEMP_ID_OWNER, "id_owner", 50, 255, $this->getVar("id_owner")), false);
74
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_TEMP_ID_BREEDER, "id_breeder", 50, 255, $this->getVar("id_breeder")), false);
75
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_TEMP_USER, "user", 50, 255, $this->getVar("user")), false);
76
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_TEMP_ROFT, "roft", 50, 255, $this->getVar("roft")), false);
77
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_TEMP_MOTHER, "mother", 50, 255, $this->getVar("mother")), false);
78
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_TEMP_FATHER, "father", 50, 255, $this->getVar("father")), false);
79
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_TEMP_FOTO, "foto", 50, 255, $this->getVar("foto")), false);
80
81
        include_once(XOOPS_ROOT_PATH . "/class/tree.php");
82
//			$Handler =& xoops_getModuleHandler("animal_", $xoopsModule->getVar("dirname"));
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...
83
        $Handler  =& xoops_getModuleHandler('pedigree_temp', $xoopsModule->getVar("dirname"));
0 ignored issues
show
Bug introduced by
The variable $xoopsModule does not exist. Did you mean $xoopsModuleConfig?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
84
        $criteria = new CriteriaCompo();
85
        $criteria->setSort('_id');
86
        $criteria->setOrder('ASC');
87
        $_arr   = $Handler->getall();
88
        $mytree = new XoopsObjectTree($_arr, "_id", "_pid");
89
        $form->addElement(new XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_TEMP_COI, $mytree->makeSelBox("_pid", "_title", "--", $this->getVar("_pid"), false)));
90
91
        $form->addElement(new XoopsFormHidden("op", "save_pedigree_temp"));
92
93
        //Submit buttons
94
        $button_tray   = new XoopsFormElementTray("", "");
95
        $submit_button = new XoopsFormButton("", "submit", _SUBMIT, "submit");
96
        $button_tray->addElement($submit_button);
97
98
        $cancel_button = new XoopsFormButton("", "", _CANCEL, "cancel");
99
        $cancel_button->setExtra('onclick="history.go(-1)"');
100
        $button_tray->addElement($cancel_button);
101
102
        $form->addElement($button_tray);
103
104
        return $form;
105
    }
106
}
107
108
/**
109
 * Class PedigreeTempHandler
110
 */
111
class PedigreeTempHandler 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...
112
{
113
    /**
114
     * @param null|object $db
115
     */
116
    function __construct(&$db)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
117
    {
118
        parent::__construct($db, "pedigree_temp", "PedigreeTemp", "ID", "NAAM");
119
    }
120
}
121