Breadcrumb   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 43
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() 4 4 1
A addLink() 7 7 1
A render() 15 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\Xnewsletter\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
 * Breadcrumb Class
16
 *
17
 * @copyright   XOOPS Project (https://xoops.org)
18
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
19
 * @author      lucio <[email protected]>
20
 * @package     xnewsletter
21
 *
22
 * Example:
23
 * $breadcrumb = new Common\Breadcrumb();
24
 * $breadcrumb->addLink( 'bread 1', 'index1.php' );
25
 * $breadcrumb->addLink( 'bread 2', '' );
26
 * $breadcrumb->addLink( 'bread 3', 'index3.php' );
27
 * echo $breadcrumb->render();
28
 */
29
use XoopsModules\Xnewsletter;
30
use XoopsModules\Xnewsletter\Common;
31
32
defined('XOOPS_ROOT_PATH') || exit('XOOPS Root Path not defined');
33
34
/**
35
 * Class Breadcrumb
36
 */
37 View Code Duplication
class Breadcrumb
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
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
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
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