Completed
Push — master ( 825da9...adb11b )
by Michael
02:15
created

Instruction   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 113
Duplicated Lines 5.31 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 6
loc 113
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A getNewInstertId() 0 5 1
C getForm() 6 74 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    /**
37
     * @return mixed
38
     */
39
    public function getNewInstertId()
40
    {
41
        $newEnreg = $GLOBALS['xoopsDB']->getInsertId();
42
        return $newEnreg;
43
    }
44
45
    // Получаем форму
46
47
    /**
48
     * @param bool|null|string $action
49
     * @return \XoopsThemeForm
50
     */
51
    public function getForm($action = false)
52
    {
53
        global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
54
        // Если нет $action
55
        if (false === $action) {
56
            $action = xoops_getenv('REQUEST_URI');
57
        }
58
        // Подключаем формы
59
        include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
60
61
        // Название формы
62
        $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDINSTR) : sprintf(_AM_INSTRUCTION_FORMEDITINSTR);
63
64
        // Форма
65
        $form = new \XoopsThemeForm($title, 'forminstr', $action, 'post', true);
66
        //$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...
67
        // Название инструкции
68
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true);
69
        // Категория
70
        $categoryHandler = new CategoryHandler;
71
        $criteria        = new \CriteriaCompo();
72
        $criteria->setSort('weight ASC, title');
73
        $criteria->setOrder('ASC');
74
        $instructioncat_arr = $categoryHandler->getall($criteria);
75
        unset($criteria);
76
        // Подключаем трей
77
        include_once $GLOBALS['xoops']->path('class/tree.php');
78
        $mytree = new \XoopsObjectTree($instructioncat_arr, 'cid', 'pid');
79
80
        // $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...
81
        $helper = Helper::getInstance();
82
        $module = $helper->getModule();
83
84 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...
85
            $mytree_select = $mytree->makeSelectElement('cid', 'title', '--', $this->getVar('cid'), true, 0, '', _AM_INSTRUCTION_CATC);
86
            $form->addElement($mytree_select);
87
        } else {
88
            $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true)));
89
        }
90
91
        // Описание
92
        $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_DESCRIPTIONC, 'description', $this->getVar('description', 'e')), true);
93
        // Статус
94
        $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false);
95
96
        // Теги
97
        $dir_tag_ok = false;
98
        if (is_dir('../../tag') || is_dir('../tag')) {
99
            $dir_tag_ok = true;
100
        }
101
        // Если влючена поддержка тегов и есть модуль tag
102
        if (xoops_getModuleOption('usetag', 'instruction') && $dir_tag_ok) {
103
            $itemIdForTag = $this->isNew() ? 0 : $this->getVar('instrid');
104
            // Подключаем форму тегов
105
            include_once $GLOBALS['xoops']->path('modules/tag/include/formtag.php');
106
            // Добавляем элемент в форму
107
            $form->addElement(new \XoopsFormTag('tag', 60, 255, $itemIdForTag, 0));
108
        }
109
110
        // Мета-теги ключевых слов
111
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'metakeywords', 50, 255, $this->getVar('metakeywords')), false);
112
        // Мета-теги описания
113
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'metadescription', 50, 255, $this->getVar('metadescription')), false);
114
115
        // Если мы редактируем категорию
116
        if (!$this->isNew()) {
117
            $form->addElement(new \XoopsFormHidden('instrid', $this->getVar('instrid')));
118
        }
119
        //
120
        $form->addElement(new \XoopsFormHidden('op', 'saveinstr'));
121
        // Кнопка
122
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
123
        return $form;
124
    }
125
}
126
127