Completed
Push — master ( db24e4...a24032 )
by Colin
02:01
created

QuoteProcessor::processInlines()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 9.3143
cc 3
eloc 10
nc 1
nop 2
crap 3
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark-extras package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * Original code based on the CommonMark JS reference parser (http://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\Extras\SmartPunct;
16
17
use League\CommonMark\Delimiter\Delimiter;
18
use League\CommonMark\Delimiter\DelimiterStack;
19
use League\CommonMark\Inline\Processor\InlineProcessorInterface;
20
21
class QuoteProcessor implements InlineProcessorInterface
22
{
23
    public function processInlines(DelimiterStack $delimiterStack, Delimiter $stackBottom = null)
24
    {
25 45
        $callback = function (Delimiter $opener, Delimiter $closer) {
26
            // Open quote
27 24
            $openerInline = $opener->getInlineNode();
28 24
            $openerInline->setContent(
29 24
                $openerInline->getContent() === '“' ? '“' : '‘'
30 24
            );
31
32
            // Close quote
33 24
            $closerInline = $closer->getInlineNode();
34 24
            $closerInline->setContent(
35 24
                $closerInline->getContent() === '“' ? '”' : '’'
36 24
            );
37
38 24
            return $closer->getNext();
39 45
        };
40
41
        // Process the emphasis characters
42 45
        $delimiterStack->iterateByCharacters(['“', '’'], $callback, $stackBottom);
43 45
    }
44
}
45