Breadcrumb   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 9.3 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 4
loc 43
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
2
3
namespace XoopsModules\Smallworld\Common;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * Breadcrumb Class
17
 *
18
 * @copyright   XOOPS Project (https://xoops.org)
19
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
20
 * @author      lucio <[email protected]>
21
 * @package     Smallworld
22
 *
23
 * Example:
24
 * $breadcrumb = new Common\Breadcrumb();
25
 * $breadcrumb->addLink( 'bread 1', 'index1.php' );
26
 * $breadcrumb->addLink( 'bread 2', '' );
27
 * $breadcrumb->addLink( 'bread 3', 'index3.php' );
28
 * echo $breadcrumb->render();
29
 */
30
31
use XoopsModules\Smallworld;
32
use XoopsModules\Smallworld\Common;
33
34
/**
35
 * Class Breadcrumb
36
 */
37
class Breadcrumb
38
{
39
    public  $dirname;
40
    private $bread = [];
41
42
    public function __construct()
43
    {
44
        $this->dirname = basename(dirname(dirname(__DIR__)));
45
    }
46
47
    /**
48
     * Add link to breadcrumb
49
     *
50
     * @param string $title
51
     * @param string $link
52
     */
53
    public function addLink($title = '', $link = '')
54
    {
55
        $this->bread[] = [
56
            'link'  => $link,
57
            'title' => $title,
58
        ];
59
    }
60
61
    /**
62
     * Render BreadCrumb
63
     */
64
    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...
65
    {
66 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...
67
            require $GLOBALS['xoops']->path('class/theme.php');
68
            $GLOBALS['xoTheme'] = new \xos_opal_Theme();
69
        }
70
71
        require $GLOBALS['xoops']->path('class/template.php');
72
        $breadcrumbTpl = new \XoopsTpl();
73
        $breadcrumbTpl->assign('breadcrumb', $this->bread);
74
        $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
75
        unset($breadcrumbTpl);
76
77
        return $html;
78
    }
79
}
80