Temp::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 13
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Pedigree;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @package         XoopsModules\Pedigree
17
 * @copyright       {@link https://xoops.org/ XOOPS Project}
18
 * @license         {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
19
 * @author          XOOPS Module Dev Team
20
 */
21
22
use XoopsModules\Pedigree\{
23
    Helper
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Pedigree\Helper. 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...
24
};
25
26
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
27
28
/**
29
 * Class Pedigree\Temp
30
 */
31
class Temp extends \XoopsObject
32
{
33
    //Constructor
34
35
    public function __construct()
36
    {
37
        parent::__construct();
38
        $this->initVar('id', \XOBJ_DTYPE_INT, null, false);
39
        $this->initVar('pname', \XOBJ_DTYPE_TXTAREA, null, true);
40
        $this->initVar('id_owner', \XOBJ_DTYPE_INT, null, false);
41
        $this->initVar('id_breeder', \XOBJ_DTYPE_INT, null, false);
42
        $this->initVar('user', \XOBJ_DTYPE_TXTBOX, null, false, 25);
43
        $this->initVar('roft', \XOBJ_DTYPE_TXTAREA, null, false);
44
        $this->initVar('mother', \XOBJ_DTYPE_INT, null, false);
45
        $this->initVar('father', \XOBJ_DTYPE_INT, null, false);
46
        $this->initVar('foto', \XOBJ_DTYPE_TXTBOX, null, false, 255);
47
        $this->initVar('coi', \XOBJ_DTYPE_TXTBOX, null, false, 10);
48
    }
49
50
    /**
51
     *
52
     * @return string name
53
     */
54
    public function __toString()
55
    {
56
        return $this->getVar('pname');
57
    }
58
59
    /**
60
     * @param bool $action
61
     *
62
     * @return \XoopsThemeForm
63
     */
64
    public function getForm($action = false)
65
    {
66
        if (false === $action) {
67
            $action = $_SERVER['REQUEST_URI'];
68
        }
69
70
        $title = $this->isNew() ? \sprintf(\_AM_PEDIGREE_PEDIGREE_TEMP_ADD) : \sprintf(\_AM_PEDIGREE_PEDIGREE_TEMP_EDIT);
71
72
        require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
73
74
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
75
        $form->setExtra('enctype="multipart/form-data"');
76
        $form->addElement(new \XoopsFormTextArea(\_AM_PEDIGREE_PEDIGREE_TEMP_PNAME, 'pname', $this->getVar('pname'), 10, 47), true);
77
        $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_TEMP_ID_OWNER, 'id_owner', 10, 11, $this->getVar('id_owner')), false);
78
        $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_TEMP_ID_BREEDER, 'id_breeder', 10, 11, $this->getVar('id_breeder')), false);
79
        $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_TEMP_USER, 'user', 25, 25, $this->getVar('user')), false);
80
        $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_TEMP_ROFT, 'roft', 2, 1, $this->getVar('roft')), false);
81
        $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_TEMP_MOTHER, 'mother', 5, 5, $this->getVar('mother')), false);
82
        $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_TEMP_FATHER, 'father', 5, 5, $this->getVar('father')), false);
83
        $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_TEMP_FOTO, 'foto', 25, 255, $this->getVar('foto')), false);
84
85
        //$Handler = xoops_getModuleHandler("animal_", $xoopsModule->getVar("dirname"));
86
        $tempHandler = Helper::getInstance()->getHandler('Temp');
87
        $criteria    = new \Criteria();
88
        $criteria->setSort('id');
0 ignored issues
show
introduced by
The method setSort() does not exist on Criteria. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

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

88
        $criteria->/** @scrutinizer ignore-call */ 
89
                   setSort('id');
Loading history...
89
        $criteria->order = 'ASC';
0 ignored issues
show
Bug introduced by
The property order does not seem to exist on Criteria.
Loading history...
90
        $tempObjArr      = $tempHandler->getAll();
0 ignored issues
show
Unused Code introduced by
The assignment to $tempObjArr is dead and can be removed.
Loading history...
Bug introduced by
The method getAll() does not exist on XoopsModules\Pedigree\TempHandler. ( Ignorable by Annotation )

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

90
        /** @scrutinizer ignore-call */ 
91
        $tempObjArr      = $tempHandler->getAll();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
        //@todo - the keys below aren't right for XoopsObjectTree. _id should be id, then need to determine which lineage (father/mother)
92
        //        and then use the appropriate key ('father', 'mother'). Can't really do a "combined" tree using XoopsObjectTree only.
93
        //$mytree = new \XoopsObjectTree($tmpObjArr, '_id', '_pid');
94
        //$form->addElement(new \XoopsFormLabel(\_AM_PEDIGREE_PEDIGREE_TEMP_COI, $mytree->makeSelBox('_pid', '_title', '--', $this->getVar('_pid'), false)));
95
        $mytree = new \XoopsObjectTree($tmpObjArr, 'id', 'coi');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tmpObjArr does not exist. Did you maybe mean $tempObjArr?
Loading history...
96
        $form->addElement($mytree->makeSelectElement(\_AM_PEDIGREE_PEDIGREE_TEMP_COI, 'coi', '--', $this->getVar('coi'), false));
97
98
        $form->addElement(new \XoopsFormHidden('op', 'save_pedigree_temp'));
99
100
        //Submit buttons
101
        $buttonTray - new \XoopsFormButtonTray('submit', _SUBMIT, 'submit', null);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $buttonTray seems to be never defined.
Loading history...
102
        /*
103
        $buttonTray = new \XoopsFormElementTray('', '');
104
        $submit_button = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
105
        $buttonTray->addElement($submit_button);
106
107
        $cancel_button = new \XoopsFormButton('', '', _CANCEL, 'cancel');
108
        $cancel_button->setExtra('onclick="history.go(-1)"');
109
        $buttonTray->addElement($cancel_button);
110
        */
111
        $form->addElement($buttonTray);
112
113
        return $form;
114
    }
115
}
116