Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

PedigreeBreadcrumb::addLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
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 33 and the first side effect is on line 28.

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
 * PedigreeBreadcrumb Class
13
 *
14
 * @copyright   The XOOPS Project http://sourceforge.net/projects/xoops/
15
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @author      lucio <[email protected]>
17
 * @package     pedigree
18
 * @since       3.23
19
 * @version     $Id: breadcrumb.php 12865 2014-11-22 07:03:35Z beckmi $
20
 *
21
 * Example:
22
 * $breadcrumb = new PedigreeBreadcrumb();
23
 * $breadcrumb->addLink( 'bread 1', 'index1.php' );
24
 * $breadcrumb->addLink( 'bread 2', '' );
25
 * $breadcrumb->addLink( 'bread 3', 'index3.php' );
26
 * echo $breadcrumb->render();
27
 */
28
defined('XOOPS_ROOT_PATH') || exit('XOOPS Root Path not defined');
29
30
/**
31
 * Class PedigreeBreadcrumb
32
 */
33
class PedigreeBreadcrumb
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
34
{
35
    public $dirname;
36
    private $bread = [];
37
38
    /**
39
     *
40
     */
41
    public function __construct()
42
    {
43
        $this->dirname = basename(dirname(__DIR__));
44
    }
45
46
    /**
47
     * Add link to breadcrumb
48
     *
49
     * @param string $title
50
     * @param string $link
51
     */
52
    public function addLink($title = '', $link = '')
53
    {
54
        $this->bread[] = [
55
            'link'  => $link,
56
            'title' => $title
57
        ];
58
    }
59
60
    /**
61
     * Render Pedigree BreadCrumb
62
     *
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...
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...
65
    {
66
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
67
            require_once $GLOBALS['xoops']->path('class/theme.php');
68
            $GLOBALS['xoTheme'] = new xos_opal_Theme();
69
        }
70
71
        require_once $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