Completed
Pull Request — master (#8)
by
unknown
08:47
created

AttributesInlineProcessor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 10 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 6
dl 3
loc 30
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C processInlines() 3 27 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This is part of the webuni/commonmark-attributes-extension package.
5
 *
6
 * (c) Martin Hasoň <[email protected]>
7
 * (c) Webuni s.r.o. <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Webuni\CommonMark\AttributesExtension;
14
15
use League\CommonMark\Block\Element\ListBlock;
16
use League\CommonMark\Block\Element\ListItem;
17
use League\CommonMark\Delimiter\Delimiter;
18
use League\CommonMark\Delimiter\DelimiterStack;
19
use League\CommonMark\Inline\Processor\InlineProcessorInterface;
20
21
class AttributesInlineProcessor implements InlineProcessorInterface
22
{
23
    public function processInlines(DelimiterStack $delimiterStack, Delimiter $stackBottom = null)
24
    {
25
        $delimiter = $delimiterStack->getTop();
26
27
        while ($delimiter !== null) {
28
            $node = $delimiter->getInlineNode();
29
            if (!$node instanceof InlineAttributes) {
30
                $delimiter = $delimiter->getPrevious();
31
                continue;
32
            }
33
34
            if ($node->isBlock()) {
35
                $target = $node->parent();
36 View Code Duplication
                if (($parent = $target->parent()) instanceof ListItem && $parent->parent() instanceof ListBlock && $parent->parent()->isTight()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
                    $target = $parent;
38
                }
39
            } else {
40
                $target = $node->previous();
41
            }
42
43
            $target->data['attributes'] = AttributesUtils::merge($node->getAttributes(), $target);
0 ignored issues
show
Bug introduced by
The property data does not seem to exist in League\CommonMark\Node\Node.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
44
45
            $node->detach();
46
47
            $delimiter = $delimiter->getPrevious();
48
        }
49
    }
50
}
51