Breadcrumb::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 4
loc 4
rs 10
c 0
b 0
f 0
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