Completed
Push — master ( a4e09c...825da9 )
by Michael
01:51
created

Instruction::getForm()   C

Complexity

Conditions 10
Paths 96

Size

Total Lines 74
Code Lines 39

Duplication

Lines 6
Ratio 8.11 %

Importance

Changes 0
Metric Value
cc 10
eloc 39
nc 96
nop 1
dl 6
loc 74
rs 5.8102
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php namespace Xoopsmodules\instruction;
2
3
//if (!defined("XOOPS_ROOT_PATH")) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
4
//	die("XOOPS root path not defined");
5
//}
6
7
include_once $GLOBALS['xoops']->path('include/common.php');
8
9
/**
10
 * Class Instruction
11
 * @package Xoopsmodules\instruction
12
 */
13
class Instruction extends \XoopsObject
14
{
15
    // constructor
16
    public function __construct()
17
    {
18
        //		$this->XoopsObject();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
19
        $this->initVar('instrid', XOBJ_DTYPE_INT, null, false, 11);
20
        $this->initVar('cid', XOBJ_DTYPE_INT, 0, false, 5);
21
        $this->initVar('uid', XOBJ_DTYPE_INT, 0, false, 11);
22
        $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false);
23
        $this->initVar('status', XOBJ_DTYPE_INT, 0, false, 1);
24
        $this->initVar('pages', XOBJ_DTYPE_INT, 0, false, 11);
25
        $this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false);
26
        $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10);
27
        $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10);
28
        $this->initVar('metakeywords', XOBJ_DTYPE_TXTBOX, '', false);
29
        $this->initVar('metadescription', XOBJ_DTYPE_TXTBOX, '', false);
30
31
        // Нет в таблице
32
        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false);
33
        $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false);
34
    }
35
36
    public function Instruction()
37
    {
38
        $this->__construct();
39
    }
40
41
    /**
42
     * @return mixed
43
     */
44
    public function get_new_enreg()
45
    {
46
        $new_enreg = $GLOBALS['xoopsDB']->getInsertId();
47
        return $new_enreg;
48
    }
49
50
    // Получаем форму
51
52
    /**
53
     * @param bool|null|string $action
54
     * @return \XoopsThemeForm
55
     */
56
    public function getForm($action = false)
57
    {
58
        global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
59
        // Если нет $action
60
        if (false === $action) {
61
            $action = xoops_getenv('REQUEST_URI');
62
        }
63
        // Подключаем формы
64
        include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
65
66
        // Название формы
67
        $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDINSTR) : sprintf(_AM_INSTRUCTION_FORMEDITINSTR);
68
69
        // Форма
70
        $form = new \XoopsThemeForm($title, 'forminstr', $action, 'post', true);
71
        //$form->setExtra('enctype="multipart/form-data"');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
72
        // Название инструкции
73
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true);
74
        // Категория
75
        $categoryHandler = new CategoryHandler;
76
        $criteria        = new \CriteriaCompo();
77
        $criteria->setSort('weight ASC, title');
78
        $criteria->setOrder('ASC');
79
        $instructioncat_arr = $categoryHandler->getall($criteria);
80
        unset($criteria);
81
        // Подключаем трей
82
        include_once $GLOBALS['xoops']->path('class/tree.php');
83
        $mytree = new \XoopsObjectTree($instructioncat_arr, 'cid', 'pid');
84
85
        // $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true)));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
86
        $helper = Helper::getInstance();
87
        $module = $helper->getModule();
88
89 View Code Duplication
        if (Utility::checkVerXoops($module, '2.5.9')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
            $mytree_select = $mytree->makeSelectElement('cid', 'title', '--', $this->getVar('cid'), true, 0, '', _AM_INSTRUCTION_CATC);
91
            $form->addElement($mytree_select);
92
        } else {
93
            $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true)));
94
        }
95
96
        // Описание
97
        $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_DESCRIPTIONC, 'description', $this->getVar('description', 'e')), true);
98
        // Статус
99
        $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false);
100
101
        // Теги
102
        $dir_tag_ok = false;
103
        if (is_dir('../../tag') || is_dir('../tag')) {
104
            $dir_tag_ok = true;
105
        }
106
        // Если влючена поддержка тегов и есть модуль tag
107
        if (xoops_getModuleOption('usetag', 'instruction') && $dir_tag_ok) {
108
            $itemIdForTag = $this->isNew() ? 0 : $this->getVar('instrid');
109
            // Подключаем форму тегов
110
            include_once $GLOBALS['xoops']->path('modules/tag/include/formtag.php');
111
            // Добавляем элемент в форму
112
            $form->addElement(new \XoopsFormTag('tag', 60, 255, $itemIdForTag, 0));
113
        }
114
115
        // Мета-теги ключевых слов
116
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'metakeywords', 50, 255, $this->getVar('metakeywords')), false);
117
        // Мета-теги описания
118
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'metadescription', 50, 255, $this->getVar('metadescription')), false);
119
120
        // Если мы редактируем категорию
121
        if (!$this->isNew()) {
122
            $form->addElement(new \XoopsFormHidden('instrid', $this->getVar('instrid')));
123
        }
124
        //
125
        $form->addElement(new \XoopsFormHidden('op', 'saveinstr'));
126
        // Кнопка
127
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
128
        return $form;
129
    }
130
}
131
132