Completed
Push — master ( 72206a...a05009 )
by Michael
11:12
created

Upgrade_2017   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 50
loc 50
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A check_auth_db() 7 7 1
A query() 7 7 2
A apply_auth_db() 16 16 3
A __construct() 5 5 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 6 and the first side effect is on line 57.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Class upgrade_2017
5
 */
6 View Code Duplication
class Upgrade_2017 extends XoopsUpgrade
0 ignored issues
show
Duplication introduced by
This class 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...
7
{
8
    /**
9
     * @return bool
10
     */
11
    public function check_auth_db()
12
    {
13
        $db    = $GLOBALS['xoopsDB'];
14
        $value = $this->getDbValue($db, 'config', 'conf_id', "`conf_name` = 'ldap_use_TLS' AND `conf_catid` = " . XOOPS_CONF_AUTH);
15
16
        return (bool)$value;
17
    }
18
19
    /**
20
     * @param $sql
21
     */
22
    protected function query($sql)
23
    {
24
        $db = $GLOBALS['xoopsDB'];
25
        if (!($ret = $db->queryF($sql))) {
26
            echo $db->error();
27
        }
28
    }
29
30
    /**
31
     * @return bool
32
     */
33
    public function apply_auth_db()
34
    {
35
        $db = $GLOBALS['xoopsDB'];
36
37
        // Insert config values
38
        $table = $db->prefix('config');
39
        $data  = array(
40
            'ldap_use_TLS' => "'_MD_AM_LDAP_USETLS', '0', '_MD_AM_LDAP_USETLS_DESC', 'yesno', 'int', 21");
41
        foreach ($data as $name => $values) {
42
            if (!$this->getDbValue($db, 'config', 'conf_id', "`conf_modid`=0 AND `conf_catid`=7 AND `conf_name`='$name'")) {
43
                $this->query("INSERT INTO `$table` (conf_modid,conf_catid,conf_name,conf_title,conf_value,conf_desc,conf_formtype,conf_valuetype,conf_order) " . "VALUES ( 0,7,'$name',$values)");
44
            }
45
        }
46
47
        return true;
48
    }
49
50
    public function __construct()
51
    {
52
        parent::__construct(basename(__DIR__));
53
        $this->tasks = array('auth_db');
54
    }
55
}
56
57
$upg = new Upgrade_2017();
58
return $upg;
59