xoops_module_update_pedigree()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 25
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
c 0
b 0
f 0
nc 5
nop 2
dl 0
loc 25
rs 9.9
1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @package     XoopsModules\Pedigree
14
 * @copyright   XOOPS Project https://xoops.org/
15
 * @license     GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author      XOOPS Development Team
17
 */
18
19
use \Xmf\Database\Tables;
20
use XoopsModules\Pedigree\{
21
  Utility
22
};
23
24
/**
25
 * Make updates to module tables, files, configs, etc. during module update
26
 *
27
 * @param \XoopsModule $module
28
 * @param string       $prev_ver
29
 *
30
 * @return bool
31
 */
32
33
function xoops_module_update_pedigree(\XoopsModule $module, string $prev_ver)
0 ignored issues
show
Unused Code introduced by
The parameter $prev_ver is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
function xoops_module_update_pedigree(\XoopsModule $module, /** @scrutinizer ignore-unused */ string $prev_ver)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
{
35
    /**
36
     * {@internal Both success and failure messages can be sent back to the calling
37
     * routine via the $module->setErrors() method. }}
38
     */
39
40
    $tableMap = [
41
        //from tablename    =>  to tablename
42
        ['from' => 'owner', 'to' => 'pedigree_owner'],
43
        ['from' => 'stamboom', 'to' => 'pedigree_registry'],
44
        ['from' => 'pedigree_config', 'to' => 'pedigree_fields'],
45
    ];
46
47
    $success = true;
48
49
    $tables = new Tables();
50
    foreach ($tableMap as $map) {
51
        $success = $success && $tables->renameTable($map['from'], $map['to']);
52
        /** @TODO move hard coded language string to language file */
53
        $msg = $success ? sprintf('Successfully renamed %s table', $map['to']) : sprintf('Failed to rename table %s to %s', $map['from'], $map['to']);
54
        $module->setErrors($msg);
55
    }
56
57
    return $success;
58
}
59