GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NewlineParser   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 6

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 6
dl 0
loc 39
ccs 18
cts 18
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCharacters() 0 4 1
B parse() 0 23 5
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <colinodell@gmail.com>
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\Inline\Parser;
16
17
use League\CommonMark\Inline\Element\Newline;
18
use League\CommonMark\Inline\Element\Text;
19
use League\CommonMark\InlineParserContext;
20
21
class NewlineParser extends AbstractInlineParser
22
{
23
    /**
24
     * @return string[]
25
     */
26 1914
    public function getCharacters()
27
    {
28 1914
        return ["\n"];
29
    }
30
31
    /**
32
     * @param InlineParserContext $inlineContext
33
     *
34
     * @return bool
35
     */
36 198
    public function parse(InlineParserContext $inlineContext)
37
    {
38 198
        $inlineContext->getCursor()->advance();
39
40
        // Check previous inline for trailing spaces
41 198
        $spaces = 0;
42 198
        $lastInline = $inlineContext->getContainer()->lastChild();
43 198
        if ($lastInline && $lastInline instanceof Text) {
44 189
            $trimmed = rtrim($lastInline->getContent(), ' ');
45 189
            $spaces = strlen($lastInline->getContent()) - strlen($trimmed);
46 189
            if ($spaces) {
47 24
                $lastInline->setContent($trimmed);
48 24
            }
49 189
        }
50
51 198
        if ($spaces >= 2) {
52 15
            $inlineContext->getContainer()->appendChild(new Newline(Newline::HARDBREAK));
53 15
        } else {
54 183
            $inlineContext->getContainer()->appendChild(new Newline(Newline::SOFTBREAK));
55
        }
56
57 198
        return true;
58
    }
59
}
60