Passed
Push — feature/6.x ( 53903f...32797a )
by Schlaefer
05:38 queued 02:15
created

CodeDefinition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 71
rs 10
c 0
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
declare(strict_types=1);
3
4
/**
5
 * Saito - The Threaded Web Forum
6
 *
7
 * @copyright Copyright (c) the Saito Project Developers
8
 * @link https://github.com/Schlaefer/Saito
9
 * @license http://opensource.org/licenses/MIT
10
 */
11
12
namespace BbcodeParser\Lib\jBBCode\Definitions;
13
14
use Cake\View\Helper;
15
use JBBCode\ElementNode;
16
use Saito\Markup\MarkupSettings;
17
18
abstract class CodeDefinition extends \JBBCode\CodeDefinition
19
{
20
    /**
21
     * @var \Cake\View\Helper calling CakePHP helper
22
     */
23
    protected $_sHelper;
24
25
    protected $_sParseContent = true;
26
27
    protected $_sUseOptions = false;
28
29
    /**
30
     * @var string bbcode-tag
31
     */
32
    protected $_sTagName;
33
34
    /**
35
     * @var array Saito-options
36
     */
37
    protected $_sOptions;
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function __construct(Helper $Helper, MarkupSettings $options)
43
    {
44
        $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...
45
        $this->_sHelper = $Helper;
46
        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

46
        /** @scrutinizer ignore-deprecated */ parent::__construct();
Loading history...
47
        $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

47
        /** @scrutinizer ignore-deprecated */ $this->setTagName($this->_sTagName);
Loading history...
48
        $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

48
        /** @scrutinizer ignore-deprecated */ $this->setParseContent($this->_sParseContent);
Loading history...
49
        $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

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