Completed
Pull Request — master (#100)
by
unknown
21:51 queued 19:53
created

LinkConverter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 68.75%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 36
ccs 11
cts 16
cp 0.6875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedTags() 0 4 1
A convert() 0 20 4
1
<?php
2
3
namespace League\HTMLToMarkdown\Converter;
4
5
use League\HTMLToMarkdown\ElementInterface;
6
7
class LinkConverter implements ConverterInterface
8
{
9
    /**
10
     * @param ElementInterface $element
11
     *
12
     * @return string
13
     */
14 3
    public function convert(ElementInterface $element)
15
    {
16 3
        $href = $element->getAttribute('href');
17 3
        $title = $element->getAttribute('title');
18 3
        $text = $element->getValue();
19
20 3
        if ($title !== '') {
21
            $markdown = '[' . $text . '](' . $href . ' "' . $title . '")';
22 3
        } elseif ($href === $text) {
23
            $markdown = '<' . $href . '>';
24
        } else {
25 3
            $markdown = '[' . $text . '](' . $href . ')';
26
        }
27
28 3
        if (!$href) {
29
            $markdown = html_entity_decode($element->getChildrenAsString());
30
        }
31
32 3
        return $markdown;
33
    }
34
35
    /**
36
     * @return string[]
37
     */
38 78
    public function getSupportedTags()
39
    {
40 78
        return array('a');
41
    }
42
}
43