Shortcode   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 96
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A get() 0 9 3
A getName() 0 4 1
A getContent() 0 4 1
A toArray() 0 4 1
A __get() 0 4 2
1
<?php namespace Webwizo\Shortcodes\Compilers;
2
3
use Illuminate\Contracts\Support\Arrayable;
4
5
class Shortcode implements Arrayable
6
{
7
    /**
8
     * Shortcode name
9
     *
10
     * @var string
11
     */
12
    protected $name;
13
14
    /**
15
     * Shortcode Attributes
16
     *
17
     * @var array
18
     */
19
    protected $attributes = [];
20
21
    /**
22
     * Shortcode content
23
     *
24
     * @var string
25
     */
26
    public $content;
27
28
    /**
29
     * Constructor
30
     *
31
     * @param string $name
32
     * @param string $content
33
     * @param array  $attributes
34
     */
35
    public function __construct($name, $content, $attributes = [])
36
    {
37
        $this->name = $name;
38
        $this->content = $content;
39
        $this->attributes = $attributes;
40
    }
41
42
    /**
43
     * Get html attribute
44
     *
45
     * @param  string $attribute
46
     *
47
     * @return string|null
48
     */
49
    public function get($attribute, $fallback = null)
50
    {
51
        $value = $this->{$attribute};
52
        if (!is_null($value)) {
53
            return $attribute . '="' . $value . '"';
54
        } elseif (!is_null($fallback)) {
55
            return $attribute . '="' . $fallback . '"';
56
        }
57
    }
58
59
    /**
60
     * Get shortcode name
61
     *
62
     * @return string
63
     */
64
    public function getName()
65
    {
66
        return $this->name;
67
    }
68
69
    /**
70
     * Get shortcode attributes
71
     *
72
     * @return string
73
     */
74
    public function getContent()
75
    {
76
        return $this->content;
77
    }
78
79
    /**
80
     * Return array of attributes;
81
     *
82
     * @return array
83
     */
84
    public function toArray()
85
    {
86
        return $this->attributes;
87
    }
88
89
    /**
90
     * Dynamically get attributes
91
     *
92
     * @param  string $param
93
     *
94
     * @return string|null
95
     */
96
    public function __get($param)
97
    {
98
        return isset($this->attributes[$param]) ? $this->attributes[$param] : null;
99
    }
100
}
101