QuoteRenderer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 18 4
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 (http://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\Extension\SmartPunct;
18
19
use League\CommonMark\Node\Node;
20
use League\CommonMark\Renderer\ChildNodeRendererInterface;
21
use League\CommonMark\Renderer\NodeRendererInterface;
22
23
final class QuoteRenderer implements NodeRendererInterface
24
{
25
    /**
26
     * @param Quote $node
27
     *
28
     * {@inheritdoc}
29
     *
30
     * @psalm-suppress MoreSpecificImplementedParamType
31
     */
32 48
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
33
    {
34 48
        if (! $node instanceof Quote) {
35 3
            throw new \InvalidArgumentException(\sprintf('Expected an instance of "%s", got "%s" instead', Quote::class, \get_class($node)));
36
        }
37
38
        // Handles unpaired quotes which remain after processing delimiters
39 45
        if ($node->getLiteral() === Quote::SINGLE_QUOTE) {
40
            // Render as an apostrophe
41 12
            return Quote::SINGLE_QUOTE_CLOSER;
42
        }
43
44 39
        if ($node->getLiteral() === Quote::DOUBLE_QUOTE) {
45
            // Render as an opening quote
46 6
            return Quote::DOUBLE_QUOTE_OPENER;
47
        }
48
49 36
        return $node->getLiteral();
50
    }
51
}
52