Shortcode   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 86
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A strip() 0 4 1
A __construct() 0 4 1
A register() 0 6 1
A enable() 0 6 1
A disable() 0 6 1
A compile() 0 8 1
1
<?php namespace Webwizo\Shortcodes;
2
3
use Webwizo\Shortcodes\Compilers\ShortcodeCompiler;
4
5
class Shortcode
6
{
7
    /**
8
     * Shortcode compiler
9
     *
10
     * @var \Webwizo\Shortcodes\Compilers\ShortcodeCompiler
11
     */
12
    protected $compiler;
13
14
    /**
15
     * Constructor
16
     *
17
     * @param \Webwizo\Shortcodes\Compilers\ShortcodeCompiler $compiler
18
     */
19
    public function __construct(ShortcodeCompiler $compiler)
20
    {
21
        $this->compiler = $compiler;
22
    }
23
24
    /**
25
     * Register a new shortcode
26
     *
27
     * @param  string          $name
28
     * @param  callable|string $callback
29
     *
30
     * @return \Webwizo\Shortcodes\Shortcode
31
     */
32
    public function register($name, $callback)
33
    {
34
        $this->compiler->add($name, $callback);
35
36
        return $this;
37
    }
38
39
    /**
40
     * Enable the laravel-shortcodes
41
     *
42
     * @return \Webwizo\Shortcodes\Shortcode
43
     */
44
    public function enable()
45
    {
46
        $this->compiler->enable();
47
48
        return $this;
49
    }
50
51
    /**
52
     * Disable the laravel-shortcodes
53
     *
54
     * @return \Webwizo\Shortcodes\Shortcode
55
     */
56
    public function disable()
57
    {
58
        $this->compiler->disable();
59
60
        return $this;
61
    }
62
63
    /**
64
     * Compile the given string
65
     *
66
     * @param  string $value
67
     *
68
     * @return string
69
     */
70
    public function compile($value)
71
    {
72
        // Always enable when we call the compile method directly
73
        $this->enable();
74
75
        // return compiled contents
76
        return $this->compiler->compile($value);
77
    }
78
79
    /**
80
     * Remove all shortcode tags from the given content.
81
     *
82
     * @param string $value
83
     *
84
     * @return string
85
     */
86
    public function strip($value)
87
    {
88
        return $this->compiler->strip($value);
89
    }
90
}
91