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

NewlineRenderer::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 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