Completed
Push — master ( 16a09f...2bada9 )
by Michael
01:30
created

XoopsheadlineUtility::xoopsheadline_getrenderer()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 1
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
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 23 and the first side effect is on line 13.

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
 *  xoopsheadline Utility Class Elements
4
 *
5
 * @copyright ::  ZySpec Incorporated
6
 * @license   ::    {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
7
 * @package   ::    xoopsheadline
8
 * @subpackage:: class
9
 * @author    ::     unknown, zyspec ([email protected])
10
 * @since     ::     File available since release 1.10
11
 */
12
13
defined('XOOPS_ROOT_PATH') || die('Restricted access');
14
15
/**
16
 * XoopsheadlineUtility
17
 *
18
 * @package  ::   xoopsheadline
19
 * @author   ::    zyspec ([email protected])
20
 * @copyright:: Copyright (c) 2010 ZySpec Incorporated, Herve Thouzard
21
 * @access::    public
22
 */
23
class XoopsheadlineUtility
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Comprehensibility Best Practice introduced by
The type XoopsheadlineUtility has been defined more than once; this definition is ignored, only the first definition in class/utility.php (L6-153) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
24
{
25
    /**
26
     * XoopsheadlineUtility
27
     *
28
     * Function to create appropriate Renderer
29
     * (based on locale)
30
     * @param $headline
31
     * @return XoopsHeadlineRenderer|XoopsHeadlineRendererLocal
32
     */
33
    public static function xoopsheadline_getrenderer(&$headline)
0 ignored issues
show
Coding Style introduced by
xoopsheadline_getrenderer uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
34
    {
35
        require_once XOOPS_ROOT_PATH . '/modules/xoopsheadline/class/headlinerenderer.php';
36
        if (file_exists(XOOPS_ROOT_PATH . '/modules/xoopsheadline/language/' . $GLOBALS['xoopsConfig']['language'] . '/headlinerenderer.php')) {
37
            require_once XOOPS_ROOT_PATH . '/modules/xoopsheadline/language/' . $GLOBALS['xoopsConfig']['language'] . '/headlinerenderer.php';
38
            if (class_exists('XoopsHeadlineRendererLocal')) {
39
                $myhl = new XoopsHeadlineRendererLocal($headline);
40
41
                return $myhl;
42
            }
43
        }
44
        $myhl = new XoopsHeadlineRenderer($headline);
45
46
        return $myhl;
47
    }
48
}
49