Conditions | 6 |
Paths | 8 |
Total Lines | 77 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
51 | public function __construct($target) |
||
52 | { |
||
53 | $moduleDirName = \basename(\dirname(\dirname(__DIR__))); |
||
54 | |||
55 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
56 | |||
57 | /** @var \XoopsModules\Tdmdownloads\Helper $this->helper */ |
||
58 | |||
59 | $this->helper = $target->helper; |
||
60 | |||
61 | $this->targetObject = $target; |
||
62 | |||
63 | $title = $this->targetObject->isNew() ? \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'FIELD_ADD')) : \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'FIELD_EDIT')); |
||
|
|||
64 | |||
65 | parent::__construct('', 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
66 | |||
67 | $this->setExtra('enctype="multipart/form-data"'); |
||
68 | |||
69 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
70 | |||
71 | $hidden = new \XoopsFormHidden('fid', $this->targetObject->getVar('cat_cid')); |
||
72 | |||
73 | $this->addElement($hidden); |
||
74 | |||
75 | unset($hidden); |
||
76 | |||
77 | $categoryHandler = new \XoopsModules\Tdmdownloads\CategoryHandler(); |
||
78 | |||
79 | $start = Request::getInt('start', 0); |
||
80 | |||
81 | $catPaginationLimit = $this->helper->getConfig('userpager') ?: 10; |
||
82 | |||
83 | $criteria = new \CriteriaCompo(); |
||
84 | |||
85 | $criteria->setOrder('DESC'); |
||
86 | |||
87 | $criteria->setLimit($catPaginationLimit); |
||
88 | |||
89 | $criteria->setStart($start); |
||
90 | |||
91 | $catCount = $categoryHandler->getCount($criteria); |
||
92 | |||
93 | $catArray = $categoryHandler->getAll($criteria); |
||
94 | |||
95 | // Form Select Category |
||
96 | |||
97 | $categoryIdSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'SELECT'), 'cat_title', $this->targetObject->getVar('cat_cid')); |
||
98 | |||
99 | $categoryIdSelect->setExtra('onchange="submit()"'); |
||
100 | |||
101 | // $categoryIdSelect->addOption(0, ' '); |
||
102 | |||
103 | foreach (\array_keys($catArray) as $i) { |
||
104 | $catName = $catArray[$i]->getVar('cat_title'); |
||
105 | |||
106 | $catPid = $catArray[$i]->getVar('cat_pid'); |
||
107 | |||
108 | if ($catPid > 0) { |
||
109 | $categoryObj = $categoryHandler->get($catPid); |
||
110 | |||
111 | if (\is_object($categoryObj)) { |
||
112 | $catName .= ' (' . $categoryObj->getVar('cat_title') . ')'; |
||
113 | } else { |
||
114 | $catName .= ' (' . \constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_CATPID') . ')'; |
||
115 | } |
||
116 | } |
||
117 | |||
118 | $categoryIdSelect->addOption($catArray[$i]->getVar('cat_cid'), $catName); |
||
119 | } |
||
120 | |||
121 | $this->addElement($categoryIdSelect); |
||
122 | |||
123 | unset($categoryCriteria); |
||
124 | |||
125 | $this->addElement(new \XoopsFormHidden('start', 0)); |
||
126 | |||
127 | $this->addElement(new \XoopsFormHidden('limit', 0)); |
||
128 | } |
||
130 |