Completed
Branch master (55a138)
by Michael
03:21
created

Breadcrumb   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 8.51 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 4
loc 47
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addLink() 0 7 1
A render() 4 15 3

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 namespace XoopsModules\Extcal\Common;
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 31 and the first side effect is on line 26.

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
 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
 * Breadcrumb Class
13
 *
14
 * @copyright   XOOPS Project (https://xoops.org)
15
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @author      lucio <[email protected]>
17
 * @package     extcal
18
 *
19
 * Example:
20
 * $breadcrumb = new PedigreeBreadcrumb();
21
 * $breadcrumb->addLink( 'bread 1', 'index1.php' );
22
 * $breadcrumb->addLink( 'bread 2', '' );
23
 * $breadcrumb->addLink( 'bread 3', 'index3.php' );
24
 * echo $breadcrumb->render();
25
 */
26
defined('XOOPS_ROOT_PATH') || exit('XOOPS Root Path not defined');
27
28
/**
29
 * Class Breadcrumb
30
 */
31
class Breadcrumb
32
{
33
    public $dirname;
34
    private $bread = [];
35
36
    /**
37
     *
38
     */
39
    public function __construct()
40
    {
41
        $this->dirname = basename(dirname(__DIR__));
42
    }
43
44
    /**
45
     * Add link to breadcrumb
46
     *
47
     * @param string $title
48
     * @param string $link
49
     */
50
    public function addLink($title = '', $link = '')
51
    {
52
        $this->bread[] = [
53
            'link'  => $link,
54
            'title' => $title
55
        ];
56
    }
57
58
    /**
59
     * Render Pedigree BreadCrumb
60
     *
61
     */
62
    public function render()
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...
Coding Style introduced by
render 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...
63
    {
64 View Code Duplication
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
65
            require_once $GLOBALS['xoops']->path('class/theme.php');
66
            $GLOBALS['xoTheme'] =  new \Xos_opal_Theme();
67
        }
68
69
        require_once $GLOBALS['xoops']->path('class/template.php');
70
        $breadcrumbTpl = new \XoopsTpl();
71
        $breadcrumbTpl->assign('breadcrumb', $this->bread);
72
        $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
73
        unset($breadcrumbTpl);
74
75
        return $html;
76
    }
77
}
78