Completed
Branch master (3308d9)
by Michael
03:00 queued 51s
created

XoopsheadlineUtility   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 27
rs 10
wmc 3
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A xoopsheadline_getrenderer() 0 16 3
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...
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
        include_once XOOPS_ROOT_PATH . '/modules/xoopsheadline/class/headlinerenderer.php';
35
        if (file_exists(XOOPS_ROOT_PATH . '/modules/xoopsheadline/language/' . $GLOBALS['xoopsConfig']['language']
36
                        . '/headlinerenderer.php')) {
37
            include_once XOOPS_ROOT_PATH . '/modules/xoopsheadline/language/' . $GLOBALS['xoopsConfig']['language']
38
                         . '/headlinerenderer.php';
39
            if (class_exists('XoopsHeadlineRendererLocal')) {
40
                $myhl = new XoopsHeadlineRendererLocal($headline);
41
42
                return $myhl;
43
            }
44
        }
45
        $myhl = new XoopsHeadlineRenderer($headline);
46
47
        return $myhl;
48
    }
49
}
50