Completed
Push — master ( 9292e6...a84270 )
by Colin
03:12 queued 02:10
created

NewlineRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfiguration() 0 4 1
A render() 0 12 3
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace League\CommonMark\Renderer\Inline;
16
17
use League\CommonMark\Configuration\ConfigurationAwareInterface;
18
use League\CommonMark\Configuration\ConfigurationInterface;
19
use League\CommonMark\Node\Inline\Newline;
20
use League\CommonMark\Node\Node;
21
use League\CommonMark\Renderer\ChildNodeRendererInterface;
22
use League\CommonMark\Renderer\NodeRendererInterface;
23
use League\CommonMark\Util\HtmlElement;
24
25
final class NewlineRenderer implements NodeRendererInterface, ConfigurationAwareInterface
26
{
27
    /** @var ConfigurationInterface */
28
    protected $config;
29
30 2496
    public function setConfiguration(ConfigurationInterface $configuration): void
31
    {
32 2496
        $this->config = $configuration;
33 2496
    }
34
35
    /**
36
     * @param Newline                    $node
37
     * @param ChildNodeRendererInterface $childRenderer
38
     *
39
     * @return HtmlElement|string
40
     */
41 276
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
42
    {
43 276
        if (!($node instanceof Newline)) {
44 3
            throw new \InvalidArgumentException('Incompatible node type: ' . \get_class($node));
45
        }
46
47 273
        if ($node->getType() === Newline::HARDBREAK) {
48 33
            return new HtmlElement('br', [], '', true) . "\n";
49
        }
50
51 240
        return $this->config->get('renderer/soft_break', "\n");
52
    }
53
}
54