Completed
Push — develop ( e54750...4239da )
by Mohamed
08:00
created

BlueBoxTrait::box()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 5
crap 1
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
use Illuminate\Html\HtmlBuilder;
15
16
/**
17
 * BlueBoxTrait is trait class for adding methods to generate the html code of the blue box.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 *
21
 * @method HtmlBuilder attributes($relations)
22
 */
23
trait BlueBoxTrait
24
{
25
    /**
26
     * Short cut method to call startBox() & endBox().
27
     *
28
     * @param string      $content
29
     * @param string      $style
30
     * @param string|null $title
31
     * @param string|null $moreLink
32
     * @param string|null $moreTitle
33
     *
34
     * @return string
35
     */
36 1
    public function box($content, $style = 'blue-box', $title = null, $moreLink = null, $moreTitle = null)
37
    {
38 1
        return $this->startBox($style, $title) . $content . $this->endBox($moreLink, $moreTitle);
39
    }
40
41
    /**
42
     * Render the open tags for box (e.g. blue box).
43
     *
44
     * @param string      $style
45
     * @param string|null $title
46
     * @param array       $attrs
47
     *
48
     * @return string
49
     */
50 19
    public function startBox($style = 'blue-box', $title = null, array $attrs = [])
51
    {
52 19
        $attrs['class'] = isset($attrs['class']) ? $attrs['class'] . ' ' . $style : $style;
53 19
        $output         = '<div ' . $this->attributes($attrs) . '><div class="inside-pad">';
54
55 19
        if (!empty($title)) {
56 5
            if (is_array($title)) {
57 5
                $title = '<a href="' . $title[1] . '">' . $title[0] . '</a>';
58
            }
59 5
            $output .= '<h4>' . $title . '</h4>';
60
        }
61
62 19
        $output .= '<div class="content">';
63
64 19
        return $output;
65
    }
66
67
    /**
68
     * Render the closing tags for the box (e.g. blue box).
69
     *
70
     * @param string|null $moreLink
71
     * @param string|null $moreTitle
72
     *
73
     * @return string
74
     */
75 19
    public function endBox($moreLink = null, $moreTitle = null)
76
    {
77 19
        $output = '</div>';
78
79 19
        if (!empty($moreLink)) {
80 1
            $moreTitle = empty($moreTitle) ? $moreTitle : $moreTitle;
81 1
            $output .= '<a href="' . $moreLink . '" class="view">' . $moreTitle . '</a>';
82
        }
83
84 19
        $output .= '</div></div>';
85
86 19
        return $output;
87
    }
88
}
89