Passed
Push — master ( b847d6...d6d54c )
by Michael
09:34 queued 05:00
created

Owner::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 9.8666
1
<?php namespace XoopsModules\Pedigree;
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 29 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
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
*/
12
/**
13
 * Pedigree module for XOOPS
14
 *
15
 * @copyright       Copyright (c) 2001-2019 {@link https://xoops.org XOOPS Project}
16
 * @license         https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
17
 * @package         XoopsModules\Pedigree\Class
18
 * @since
19
 * @author          XOOPS Module Dev Team (https://xoops.org)
20
 */
21
22
use XoopsModules\Pedigree;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Pedigree\Pedigree. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
23
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
26
/**
27
 * Class Pedigree\Owner
28
 */
29
class Owner extends \XoopsObject
30
{
31
    //Constructor
32
    /**
33
     *
34
     */
35
    public function __construct()
36
    {
37
        parent::__construct();
38
        $this->initVar('id', XOBJ_DTYPE_INT, null, false, 11);
39
        $this->initVar('firstname', XOBJ_DTYPE_TXTBOX, null, false, 30);
40
        $this->initVar('lastname', XOBJ_DTYPE_TXTBOX, null, false, 30);
41
        $this->initVar('postcode', XOBJ_DTYPE_TXTBOX, null, false, 7);
42
        $this->initVar('city', XOBJ_DTYPE_TXTBOX, null, false, 50);
43
        $this->initVar('streetname', XOBJ_DTYPE_TXTBOX, null, false, 40);
44
        $this->initVar('housenumber', XOBJ_DTYPE_TXTBOX, null, false, 6);
45
        $this->initVar('phonenumber', XOBJ_DTYPE_TXTBOX, null, false, 14);
46
        $this->initVar('emailadres', XOBJ_DTYPE_TXTBOX, null, false, 40);
47
        $this->initVar('website', XOBJ_DTYPE_TXTBOX, null, false, 60);
48
        $this->initVar('user', XOBJ_DTYPE_TXTBOX, null, false, 20);
49
    }
50
51
    /**
52
     * @param bool $action
53
     *
54
     * @return \XoopsThemeForm
55
     */
56
    public function getForm($action = false)
57
    {
58
        //global $xoopsModuleConfig;
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...
59
60
        if (false === $action) {
61
            $action = $_SERVER['REQUEST_URI'];
62
        }
63
        /** @var \XoopsModules\Pedigree\Helper $helper */
64
        $helper =  XoopsModules\Pedigree\Helper::getInstance();
0 ignored issues
show
Bug introduced by
The type XoopsModules\Pedigree\XoopsModules\Pedigree\Helper was not found. Did you mean XoopsModules\Pedigree\Helper? If so, make sure to prefix the type with \.
Loading history...
65
        $helper->loadLanguage('admin');
66
        $title = $this->isNew() ? sprintf(_AM_PEDIGREE_OWNER_ADD) : sprintf(_AM_PEDIGREE_OWNER_EDIT);
67
68
        require_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);
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('firstname') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

73
        $form->addElement(new \XoopsFormText(_AM_PEDIGREE_OWNER_FIRSTNAME, 'firstname', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('firstname')), false);
Loading history...
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 tray
87
        $form->addElement(new \XoopsFormButtonTray('submit', _SUBMIT));
88
        /*
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...
89
        //Submit buttons
90
        $button_tray   = new \XoopsFormElementTray('', '');
91
        $submit_button = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
92
        $button_tray->addElement($submit_button);
93
94
        $cancel_button = new \XoopsFormButton('', '', _CANCEL, 'cancel');
95
        $cancel_button->setExtra('onclick="history.go(-1)"');
96
        $button_tray->addElement($cancel_button);
97
98
        $form->addElement($button_tray);
99
        */
100
101
        return $form;
102
    }
103
}
104