These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace League\HTMLToMarkdown\Converter; |
||
4 | |||
5 | use League\HTMLToMarkdown\Configuration; |
||
6 | use League\HTMLToMarkdown\ConfigurationAwareInterface; |
||
7 | use League\HTMLToMarkdown\ElementInterface; |
||
8 | |||
9 | View Code Duplication | class DefaultConverter implements ConverterInterface, ConfigurationAwareInterface |
|
0 ignored issues
–
show
|
|||
10 | { |
||
11 | const DEFAULT_CONVERTER = '_default'; |
||
12 | |||
13 | /** |
||
14 | * @var Configuration |
||
15 | */ |
||
16 | protected $config; |
||
17 | |||
18 | /** |
||
19 | * @param Configuration $config |
||
20 | */ |
||
21 | 87 | public function setConfig(Configuration $config) |
|
22 | { |
||
23 | 87 | $this->config = $config; |
|
24 | 87 | } |
|
25 | |||
26 | /** |
||
27 | * @param ElementInterface $element |
||
28 | * |
||
29 | * @return string |
||
30 | */ |
||
31 | 81 | public function convert(ElementInterface $element) |
|
32 | { |
||
33 | // If strip_tags is false (the default), preserve tags that don't have Markdown equivalents, |
||
34 | // such as <span> nodes on their own. C14N() canonicalizes the node to a string. |
||
35 | // See: http://www.php.net/manual/en/domnode.c14n.php |
||
36 | 81 | if ($this->config->getOption('strip_tags', false)) { |
|
37 | 18 | return $element->getValue(); |
|
38 | } |
||
39 | |||
40 | 72 | return html_entity_decode($element->getChildrenAsString()); |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return string[] |
||
45 | */ |
||
46 | 87 | public function getSupportedTags() |
|
47 | { |
||
48 | 87 | return array(self::DEFAULT_CONVERTER); |
|
49 | } |
||
50 | } |
||
51 |
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.