Completed
Push — master ( d44ef5...c7e879 )
by Fèvre
12s
created

ReplyParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
namespace Xetaravel\Markdown\Reply;
3
4
use League\CommonMark\Block\Element\HtmlInline;
5
use League\CommonMark\Block\Parser\AbstractBlockParser;
6
use League\CommonMark\ContextInterface;
7
use League\CommonMark\Cursor;
8
use League\CommonMark\Util\RegexHelper;
9
10
class ReplyParser extends AbstractBlockParser
11
{
12
13
    const REGEXP_REPLY = '/\@(?<user>[\w]{4,20})\#(?<post>[0-9]{1,16})/';
14
15
    /**
16
     * Parse a line and determine if it contains an emoji. If it does,
17
     * then we do the necessary.
18
     *
19
     * @param \League\CommonMark\InlineParserContext $inlineContext
0 ignored issues
show
Documentation introduced by
There is no parameter named $inlineContext. Did you maybe mean $context?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
20
     *
21
     * @return bool
22
     */
23
    public function parse(ContextInterface $context, Cursor $cursor)
24
    {
25
        $matches = RegexHelper::matchAll(self::REGEXP_REPLY, $cursor->getLine());
26
27
        if (null === $matches) {
28
            return false;
29
        }
30
        $route = route('discuss.post.show', ['id' => $matches['post']]);
31
32
        $reply = new Reply($route, $matches['user']);
33
34
        $cursor->advanceBy(strlen($matches[0]));
35
        $context->addBlock($reply);
36
37
        return true;
38
    }
39
}
40