Completed
Push — latest ( 609def...dcbb7e )
by Colin
14s queued 11s
created

Extension/Footnote/Parser/FootnoteStartParser.php (3 issues)

Labels
Severity
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 * (c) Rezo Zero / Ambroise Maupate
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace League\CommonMark\Extension\Footnote\Parser;
16
17
use League\CommonMark\Parser\Block\BlockStart;
18
use League\CommonMark\Parser\Block\BlockStartParserInterface;
19
use League\CommonMark\Parser\Cursor;
20
use League\CommonMark\Parser\MarkdownParserStateInterface;
21
use League\CommonMark\Reference\Reference;
22
use League\CommonMark\Util\RegexHelper;
23
24
final class FootnoteStartParser implements BlockStartParserInterface
25
{
26 78
    public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart
27
    {
28 78
        if ($cursor->isIndented() || $parserState->getLastMatchedBlockParser()->canHaveLazyContinuationLines()) {
29 6
            return BlockStart::none();
1 ignored issue
show
Are you sure the usage of League\CommonMark\Parser\Block\BlockStart::none() targeting League\CommonMark\Parser\Block\BlockStart::none() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
30
        }
31
32 78
        $match = RegexHelper::matchFirst(
33
            '/^\[\^([^\s^\]]+)\]\:(?:\s|$)/',
34 78
            $cursor->getLine(),
35 78
            $cursor->getNextNonSpacePosition()
36
        );
37
38 78
        if (! $match) {
39 9
            return BlockStart::none();
1 ignored issue
show
Are you sure the usage of League\CommonMark\Parser\Block\BlockStart::none() targeting League\CommonMark\Parser\Block\BlockStart::none() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
40
        }
41
42 75
        $cursor->advanceToNextNonSpaceOrTab();
43 75
        $cursor->advanceBy(\strlen($match[0]));
44 75
        $str = $cursor->getRemainder();
45 75
        \preg_replace('/^\[\^([^\s^\]]+)\]\:(?:\s|$)/', '', $str);
46
47 75
        if (\preg_match('/^\[\^([^\s^\]]+)\]\:(?:\s|$)/', $match[0], $matches) !== 1) {
48
            return BlockStart::none();
1 ignored issue
show
Are you sure the usage of League\CommonMark\Parser\Block\BlockStart::none() targeting League\CommonMark\Parser\Block\BlockStart::none() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
49
        }
50
51 75
        $reference      = new Reference($matches[1], $matches[1], $matches[1]);
52 75
        $footnoteParser = new FootnoteParser($reference);
53
54 75
        return BlockStart::of($footnoteParser)->at($cursor);
55
    }
56
}
57