Completed
Branch master (00e474)
by Michael
05:07
created

functions.php ➔ oledrion_get_config_handler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
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
 * oledrion
14
 *
15
 * @copyright   The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 * @version     $Id: functions.php 12290 2014-02-07 11:05:17Z beckmi $
19
 */
20
function oledrion_adminMenu($currentoption = 0, $breadcrumb = '')
0 ignored issues
show
Unused Code introduced by
The parameter $currentoption is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $breadcrumb is not used and could be removed.

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

Loading history...
21
{
22
23
}
24
25
/**
26
 * Internal function
27
 */
28
function oledrion_get_mid()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
29
{
30
    global $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
31
32
    return $xoopsModule->getVar('mid');
33
34
}
35
36
/**
37
 * Internal function
38
 */
39
function oledrion_get_config_handler()
40
{
41
    $config_handler = null;
0 ignored issues
show
Unused Code introduced by
$config_handler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
    $config_handler = xoops_gethandler('config');
43
    if (!is_object($config_handler)) {
44
        trigger_error("Error, unable to get and handler on the Config object");
45
        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function oledrion_get_config_handler() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
46
    } else {
47
        return $config_handler;
48
    }
49
50
}
51
52
/**
53
 * Returns a module option
54
 *
55
 * @param string    $option_name    The module's option
0 ignored issues
show
Bug introduced by
There is no parameter named $option_name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
56
 * @return object    The requested module's option
57
 */
58
function oledrion_get_module_option($optionName = '')
59
{
60
    $ret = null;
61
    $tbl_options = array();
0 ignored issues
show
Unused Code introduced by
$tbl_options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
    $mid = oledrion_get_mid();
63
    $config_handler = oledrion_get_config_handler();
64
    $critere = new CriteriaCompo();
65
    $critere->add(new Criteria('conf_modid', $mid, '='));
66
    $critere->add(new Criteria('conf_name', $optionName, '='));
67
    $tbl_options = $config_handler->getConfigs($critere, false, false);
68
    if (count($tbl_options) > 0) {
69
        $option = $tbl_options[0];
70
        $ret = $option;
71
    }
72
73
    return $ret;
74
}
75
76
/**
77
 * Set a module's option
78
 */
79
function oledrion_set_module_option($optionName = '', $optionValue = '')
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
80
{
81
    $config_handler = oledrion_get_config_handler();
82
    $option = oledrion_get_module_option($optionName, true);
0 ignored issues
show
Unused Code introduced by
The call to oledrion_get_module_option() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
83
    $option->setVar('conf_value', $optionValue);
84
    $retval = $config_handler->insertConfig($option, true);
85
86
    return $retval;
87
}
88
89
/**
90
 * Affichage du pied de page de l'administration
91
 *
92
 * @return string    La chaine à afficher
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
93
 */
94
function show_footer()
95
{
96
//	echo "<br /><br /><div align='center'><a href='http://www.herve-thouzard.com/' target='_blank'><img src='../assets/images/instantzero.gif'></a></div>";
97
}
98