NewlineRenderer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
dl 0
loc 32
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0

2 Methods

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