TabTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 59
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tabElementActive() 0 4 2
A tabElementTitle() 0 6 1
A tab() 0 21 2
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Extensions\Html\Traits;
13
14
/**
15
 * TabTrait is trait class for adding methods to generate the html code of the bootstrap tab.
16
 *
17
 * @author Mohamed Alsharaf <[email protected]>
18
 *
19
 * @method string link($url, $title = null, $attributes = array(), $secure = null)
20
 */
21
trait TabTrait
22
{
23
    /**
24
     * Render tab header from an array.
25
     *
26
     * @param array  $tabs
27
     * @param string $active
28
     *
29
     * @return string
30
     */
31 39
    public function tab(array $tabs, $active)
32
    {
33
        $defaultTab = [
34 39
            'title'  => '',
35
            'prefix' => '',
36
            'active' => false,
37
            'url'    => '',
38
        ];
39
40 39
        $output = '<ul class="nav nav-tabs">';
41 39
        foreach ($tabs as $tab) {
42 39
            $tab = array_replace($defaultTab, $tab);
43
44 39
            $output .= '<li role="presentation" ' . $this->tabElementActive($tab, $active) . '>';
45 39
            $output .= $this->tabElementTitle($tab);
46 39
            $output .= '</li>';
47
        }
48 39
        $output .= '</ul>';
49
50 39
        return $output;
51
    }
52
53
    /**
54
     * Whether or not the tab element is active.
55
     *
56
     * @param array  $tab
57
     * @param string $active
58
     *
59
     * @return string
60
     */
61 39
    protected function tabElementActive($tab, $active)
62
    {
63 39
        return $active == $tab['page'] ? 'class="active"' : '';
64
    }
65
66
    /**
67
     * Generate the content of a tab element.
68
     *
69
     * @param array $tab
70
     *
71
     * @return string
72
     */
73 39
    protected function tabElementTitle($tab)
74
    {
75 39
        $title = trim($tab['prefix'] . ' ' . trans('tinyissue.' . $tab['page']));
76
77 39
        return $this->link($tab['url'], $title);
78
    }
79
}
80