CodeDefinition   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 72
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A asHtml() 0 12 3
A __get() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace Plugin\BbcodeParser\src\Lib\jBBCode\Definitions;
14
15
use Cake\View\Helper;
16
use JBBCode\ElementNode;
17
use Saito\Markup\MarkupSettings;
18
19
abstract class CodeDefinition extends \JBBCode\CodeDefinition
20
{
21
22
    /**
23
     * @var Helper calling CakePHP helper
24
     */
25
    protected $_sHelper;
26
27
    protected $_sParseContent = true;
28
29
    protected $_sUseOptions = false;
30
31
    /**
32
     * @var string bbcode-tag
33
     */
34
    protected $_sTagName;
35
36
    /**
37
     * @var array Saito-options
38
     */
39
    protected $_sOptions;
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function __construct(Helper $Helper, MarkupSettings $options)
45
    {
46
        $this->_sOptions = $options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options of type Saito\Markup\MarkupSettings is incompatible with the declared type array of property $_sOptions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
        $this->_sHelper = $Helper;
48
        parent::__construct();
0 ignored issues
show
Deprecated Code introduced by
The function JBBCode\CodeDefinition::__construct() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
        /** @scrutinizer ignore-deprecated */ parent::__construct();
Loading history...
49
        $this->setTagName($this->_sTagName);
0 ignored issues
show
Deprecated Code introduced by
The function JBBCode\CodeDefinition::setTagName() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

49
        /** @scrutinizer ignore-deprecated */ $this->setTagName($this->_sTagName);
Loading history...
50
        $this->setParseContent($this->_sParseContent);
0 ignored issues
show
Deprecated Code introduced by
The function JBBCode\CodeDefinition::setParseContent() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

50
        /** @scrutinizer ignore-deprecated */ $this->setParseContent($this->_sParseContent);
Loading history...
51
        $this->setUseOption($this->_sUseOptions);
0 ignored issues
show
Deprecated Code introduced by
The function JBBCode\CodeDefinition::setUseOption() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

51
        /** @scrutinizer ignore-deprecated */ $this->setUseOption($this->_sUseOptions);
Loading history...
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    public function __get($name)
58
    {
59
        if (is_object($this->_sHelper->$name)) {
60
            return $this->_sHelper->{$name};
61
        }
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67
    public function asHtml(ElementNode $el)
68
    {
69
        if (!$this->hasValidInputs($el)) {
70
            return $el->getAsBBCode();
71
        }
72
        $content = $this->getContent($el);
73
        $parsedString = $this->_parse($content, $el->getAttribute(), $el);
74
        if ($parsedString === false) {
75
            return $el->getAsBBCode();
76
        }
77
78
        return $parsedString;
79
    }
80
81
    /**
82
     * Parse
83
     *
84
     * @param string $content content
85
     * @param array $attributes attributes
86
     * @param ElementNode $node node
87
     *
88
     * @return mixed parsed string or bool false if parsing failed
89
     */
90
    abstract protected function _parse($content, $attributes, ElementNode $node);
91
}
92