UploadForm   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 44 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Tdmdownloads\Form;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 * Module: Tdmdownloads
19
 *
20
 * @category        Module
21
 * @package         tdmdownloads
22
 * @author          XOOPS Development Team <https://xoops.org>
23
 * @copyright       {@link https://xoops.org/ XOOPS Project}
24
 * @license         GPL 2.0 or later
25
 * @link            https://xoops.org/
26
 * @since           1.0.0
27
 */
28
29
use Xmf\Request;
30
use XoopsModules\Tdmdownloads;
31
32
require_once \dirname(__DIR__, 2) . '/include/common.php';
33
//$moduleDirName = basename(dirname(dirname(__DIR__)));
34
//$helper = Tdmdownloads\Helper::getInstance();
35
$permHelper = new \Xmf\Module\Helper\Permission();
36
\xoops_load('XoopsFormLoader');
37
38
/**
39
 * Class FieldForm
40
 */
41
class UploadForm extends \XoopsThemeForm
42
{
43
    public $targetObject;
44
    public $helper;
45
46
    /**
47
     * Constructor
48
     *
49
     * @param \XoopsModules\Tdmdownloads\Category $target
50
     */
51
    public function __construct($target)
52
    {
53
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
54
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
55
        /** @var \XoopsModules\Tdmdownloads\Helper $this- >helper */
56
        $this->helper       = $target->helper;
57
        $this->targetObject = $target;
58
        $title              = $this->targetObject->isNew() ? \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'FIELD_ADD')) : \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'FIELD_EDIT'));
0 ignored issues
show
Unused Code introduced by
The assignment to $title is dead and can be removed.
Loading history...
59
        parent::__construct('', 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
60
        $this->setExtra('enctype="multipart/form-data"');
61
        //include ID field, it's needed so the module knows if it is a new form or an edited form
62
        $hidden = new \XoopsFormHidden('fid', $this->targetObject->getVar('cat_cid'));
0 ignored issues
show
Bug introduced by
It seems like $this->targetObject->getVar('cat_cid') can also be of type array and array; however, parameter $value of XoopsFormHidden::__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

62
        $hidden = new \XoopsFormHidden('fid', /** @scrutinizer ignore-type */ $this->targetObject->getVar('cat_cid'));
Loading history...
63
        $this->addElement($hidden);
64
        unset($hidden);
65
        $categoryHandler    = new \XoopsModules\Tdmdownloads\CategoryHandler();
66
        $start              = Request::getInt('start', 0);
67
        $catPaginationLimit = $this->helper->getConfig('userpager') ?: 10;
68
        $criteria           = new \CriteriaCompo();
69
        $criteria->setOrder('DESC');
70
        $criteria->setLimit($catPaginationLimit);
71
        $criteria->setStart($start);
72
        $catCount = $categoryHandler->getCount($criteria);
0 ignored issues
show
Unused Code introduced by
The assignment to $catCount is dead and can be removed.
Loading history...
73
        $catArray = $categoryHandler->getAll($criteria);
74
        // Form Select Category
75
        $categoryIdSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'SELECT'), 'cat_title', $this->targetObject->getVar('cat_cid'));
76
        $categoryIdSelect->setExtra('onchange="submit()"');
77
        //        $categoryIdSelect->addOption(0, '&nbsp;');
78
        foreach (\array_keys($catArray) as $i) {
79
            $catName = $catArray[$i]->getVar('cat_title');
80
            $catPid  = $catArray[$i]->getVar('cat_pid');
81
            if ($catPid > 0) {
82
                $categoryObj = $categoryHandler->get($catPid);
83
                if (\is_object($categoryObj)) {
84
                    $catName .= ' (' . $categoryObj->getVar('cat_title') . ')';
85
                } else {
86
                    $catName .= ' (' . \constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_CATPID') . ')';
87
                }
88
            }
89
            $categoryIdSelect->addOption($catArray[$i]->getVar('cat_cid'), $catName);
90
        }
91
        $this->addElement($categoryIdSelect);
92
        unset($categoryCriteria);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $categoryCriteria seems to be never defined.
Loading history...
93
        $this->addElement(new \XoopsFormHidden('start', 0));
94
        $this->addElement(new \XoopsFormHidden('limit', 0));
95
    }
96
}
97