Conditions | 6 |
Paths | 8 |
Total Lines | 55 |
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 namespace XoopsModules\Tdmdownloads\Form; |
||
49 | public function __construct($target) |
||
50 | { |
||
51 | $moduleDirName = basename(dirname(dirname(__DIR__))); |
||
52 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||
53 | /** @var \XoopsModules\Tdmdownloads\Helper $this->helper */ |
||
54 | $this->helper = $target->helper; |
||
55 | $this->targetObject = $target; |
||
56 | |||
57 | $title = $this->targetObject->isNew() ? sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'FIELD_ADD')) : sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'FIELD_EDIT')); |
||
|
|||
58 | parent::__construct('', 'form', xoops_getenv('PHP_SELF'), 'post', true); |
||
59 | $this->setExtra('enctype="multipart/form-data"'); |
||
60 | |||
61 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
62 | |||
63 | $hidden = new \XoopsFormHidden('fid', $this->targetObject->getVar('cat_cid')); |
||
64 | $this->addElement($hidden); |
||
65 | unset($hidden); |
||
66 | |||
67 | |||
68 | $categoryHandler = new \XoopsModules\Tdmdownloads\CategoryHandler(); |
||
69 | $start = Request::getInt('start', 0); |
||
70 | $catPaginationLimit = $this->helper->getConfig('userpager') ?: 10; |
||
71 | |||
72 | $criteria = new \CriteriaCompo(); |
||
73 | $criteria->setOrder('DESC'); |
||
74 | $criteria->setLimit($catPaginationLimit); |
||
75 | $criteria->setStart($start); |
||
76 | |||
77 | $catCount = $categoryHandler->getCount($criteria); |
||
78 | $catArray = $categoryHandler->getAll($criteria); |
||
79 | |||
80 | // Form Select Category |
||
81 | $categoryIdSelect = new \XoopsFormSelect( constant('CO_' . $moduleDirNameUpper . '_' . 'SELECT'), 'cat_title', $this->targetObject->getVar('cat_cid')); |
||
82 | $categoryIdSelect->setExtra('onchange="submit()"'); |
||
83 | // $categoryIdSelect->addOption(0, ' '); |
||
84 | |||
85 | foreach(array_keys($catArray) as $i) { |
||
86 | $catName = $catArray[$i]->getVar('cat_title'); |
||
87 | $catPid = $catArray[$i]->getVar('cat_pid'); |
||
88 | if ( 0 < $catPid ) { |
||
89 | $categoryObj = $categoryHandler->get($catPid); |
||
90 | if (is_object( $categoryObj)) { |
||
91 | $catName .= ' (' . $categoryObj->getVar('cat_title') . ')'; |
||
92 | } else { |
||
93 | $catName .= ' (' . constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_CATPID') . ')'; |
||
94 | } |
||
95 | } |
||
96 | $categoryIdSelect->addOption($catArray[$i]->getVar('cat_cid'), $catName); |
||
97 | } |
||
98 | |||
99 | $this->addElement($categoryIdSelect); |
||
100 | unset($categoryCriteria); |
||
101 | |||
102 | $this->addElement(new \XoopsFormHidden('start', 0)); |
||
103 | $this->addElement(new \XoopsFormHidden('limit', 0)); |
||
104 | } |
||
106 |