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;
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     xnewsletter
22
 * @since       1.3
23
 *
24
 * Example:
25
 * $breadcrumb = new Breadcrumb();
26
 * $breadcrumb->addLink( 'bread 1', 'index1.php' );
27
 * $breadcrumb->addLink( 'bread 2', '' );
28
 * $breadcrumb->addLink( 'bread 3', 'index3.php' );
29
 * echo $breadcrumb->render();
30
 */
31 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...
32
{
33
    public  $dirname;
34
    private $bread = [];
35
36
    public function __construct()
37
    {
38
        $this->dirname = basename(dirname(__DIR__));
39
    }
40
41
    /**
42
     * Add link to breadcrumb
43
     *
44
     * @param string $title
45
     * @param string $link
46
     */
47
    public function addLink($title = '', $link = '')
48
    {
49
        $this->bread[] = [
50
            'link'  => $link,
51
            'title' => $title,
52
        ];
53
    }
54
55
    /**
56
     * Render xnewsletter BreadCrumb
57
     */
58
    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...
59
    {
60
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
61
            require_once $GLOBALS['xoops']->path('/class/theme.php');
62
            $GLOBALS['xoTheme'] = new \xos_opal_Theme();
63
        }
64
65
        require_once $GLOBALS['xoops']->path('class/template.php');
66
        $breadcrumbTpl = new \XoopsTpl();
67
        $breadcrumbTpl->assign('breadcrumb', $this->bread);
68
        $html = $breadcrumbTpl->fetch("db:{$this->dirname}_common_breadcrumb.tpl");
69
        unset($breadcrumbTpl);
70
71
        return $html;
72
    }
73
}
74