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

PedigreeOwner::getForm()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 41
Code Lines 27

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 41
rs 8.8571
cc 3
eloc 27
nc 4
nop 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 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 PedigreeOwner
29
 */
30
class PedigreeOwner 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("firstname", XOBJ_DTYPE_TXTBOX, null, false, 30);
41
        $this->initVar("lastname", XOBJ_DTYPE_TXTBOX, null, false, 30);
42
        $this->initVar("postcode", XOBJ_DTYPE_TXTBOX, null, false, 7);
43
        $this->initVar("city", XOBJ_DTYPE_TXTBOX, null, false, 50);
44
        $this->initVar("streetname", XOBJ_DTYPE_TXTBOX, null, false, 40);
45
        $this->initVar("housenumber", XOBJ_DTYPE_TXTBOX, null, false, 6);
46
        $this->initVar("phonenumber", XOBJ_DTYPE_TXTBOX, null, false, 14);
47
        $this->initVar("emailadres", XOBJ_DTYPE_TXTBOX, null, false, 40);
48
        $this->initVar("website", XOBJ_DTYPE_TXTBOX, null, false, 60);
49
        $this->initVar("user", XOBJ_DTYPE_TXTBOX, null, false, 20);
50
51
    }
52
53
    /**
54
     * @param bool $action
55
     *
56
     * @return XoopsThemeForm
57
     */
58
    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...
59
    {
60
        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...
61
62
        if ($action === false) {
63
            $action = $_SERVER["REQUEST_URI"];
64
        }
65
66
        $title = $this->isNew() ? sprintf(_AM_PEDIGREE_OWNER_ADD) : sprintf(_AM_PEDIGREE_OWNER_EDIT);
67
68
        include_once(XOOPS_ROOT_PATH . "/class/xoopsformloader.php");
69
70
        $form = new XoopsThemeForm($title, "form", $action, "post", true);
71
        $form->setExtra('enctype="multipart/form-data"');
72
73
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_FIRSTNAME, "firstname", 50, 255, $this->getVar("firstname")), false);
74
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_LASTNAME, "lastname", 50, 255, $this->getVar("lastname")), false);
75
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_POSTCODE, "postcode", 50, 255, $this->getVar("postcode")), false);
76
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_CITY, "city", 50, 255, $this->getVar("city")), false);
77
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_STREETNAME, "streetname", 50, 255, $this->getVar("streetname")), false);
78
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_HOUSENUMBER, "housenumber", 50, 255, $this->getVar("housenumber")), false);
79
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_PHONENUMBER, "phonenumber", 50, 255, $this->getVar("phonenumber")), false);
80
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_EMAILADRES, "emailadres", 50, 255, $this->getVar("emailadres")), false);
81
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_WEBSITE, "website", 50, 255, $this->getVar("website")), false);
82
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_USER, "user", 50, 255, $this->getVar("user")), false);
83
84
        $form->addElement(new XoopsFormHidden("op", "save_owner"));
85
86
        //Submit buttons
87
        $button_tray   = new XoopsFormElementTray("", "");
88
        $submit_button = new XoopsFormButton("", "submit", _SUBMIT, "submit");
89
        $button_tray->addElement($submit_button);
90
91
        $cancel_button = new XoopsFormButton("", "", _CANCEL, "cancel");
92
        $cancel_button->setExtra('onclick="history.go(-1)"');
93
        $button_tray->addElement($cancel_button);
94
95
        $form->addElement($button_tray);
96
97
        return $form;
98
    }
99
}
100
101
/**
102
 * Class PedigreeOwnerHandler
103
 */
104
class PedigreeOwnerHandler 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|object $db
108
     */
109
    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...
110
    {
111
        parent::__construct($db, "pedigree_owner", "PedigreeOwner", "ID", "firstname");
112
    }
113
}
114