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

InstructionHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 18 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 9
loc 50
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A updateDateupdated() 9 9 2
A updatePages() 0 16 1

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
//use Xoopsmodules\instruction;
4
5
//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...
6
//	die("XOOPS root path not defined");
7
//}
8
9
//include_once $GLOBALS['xoops']->path('include/common.php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
10
11
/**
12
 * Class InstructionHandler
13
 * @package Xoopsmodules\instruction
14
 */
15
class InstructionHandler extends \XoopsPersistableObjectHandler
16
{
17
    /**
18
     * @param null|mixed $db
19
     */
20
    public function __construct(\XoopsDatabase $db = null)
21
    {
22
        parent::__construct($db, 'instruction_instr', Instruction::class, 'instrid', 'title');
23
    }
24
25
    // Обновление даты обновления инструкций
26
27
    /**
28
     * @param int  $instrid
29
     * @param bool|int $time
30
     * @return mixed
31
     */
32 View Code Duplication
    public function updateDateupdated($instrid = 0, $time = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
33
    {
34
        // Если не передали время
35
        $time = null === $time ? time() : (int)$time;
36
        //
37
        $sql = sprintf('UPDATE `%s` SET `dateupdated` = %u WHERE `instrid` = %u', $this->table, $time, (int)$instrid);
38
        //
39
        return $this->db->query($sql);
40
    }
41
42
    // Обновление числа страниц
43
44
    /**
45
     * @param int $instrid
46
     * @return mixed
47
     */
48
    public function updatePages($instrid = 0)
49
    {
50
        //        $pageHandler = xoops_getModuleHandler('page', 'instruction');
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
51
        // Находим число активных страниц
52
        $criteria = new \CriteriaCompo();
53
        $criteria->add(new \Criteria('instrid', $instrid, '='));
54
        $criteria->add(new \Criteria('status ', '0', '>'));
55
        // Число страниц
56
        $pages = $pageHandler->getCount($criteria);
0 ignored issues
show
Bug introduced by
The variable $pageHandler does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
57
        unset($criteria);
58
59
        // Сохраняем это число
60
        $sql = sprintf('UPDATE `%s` SET `pages` = %u, `dateupdated` = %u WHERE `instrid` = %u', $this->table, $pages, time(), $instrid);
61
        //
62
        return $this->db->query($sql);
63
    }
64
}
65