DelimiterStack::push()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
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 (https://bitly.com/commonmark-js)
11
 *  - (c) John MacFarlane
12
 *
13
 * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java)
14
 *  - (c) Atlassian Pty Ltd
15
 *
16
 * For the full copyright and license information, please view the LICENSE
17
 * file that was distributed with this source code.
18
 */
19
20
namespace League\CommonMark\Delimiter;
21
22
use League\CommonMark\Delimiter\Processor\CacheableDelimiterProcessorInterface;
23
use League\CommonMark\Delimiter\Processor\DelimiterProcessorCollection;
24
use League\CommonMark\Node\Inline\AdjacentTextMerger;
25
use League\CommonMark\Node\Node;
26
27
final class DelimiterStack
28
{
29
    /** @psalm-readonly-allow-private-mutation */
30
    private ?DelimiterInterface $top = null;
31
32
    /** @psalm-readonly-allow-private-mutation */
33
    private ?Bracket $brackets = null;
34
35
    /**
36
     * @deprecated This property will be removed in 3.0 once all delimiters MUST have an index/position
37
     *
38
     * @var \SplObjectStorage<DelimiterInterface, int>|\WeakMap<DelimiterInterface, int>
39
     */
40
    private $missingIndexCache;
41
42
43
    private int $remainingDelimiters = 0;
44
45 2190
    public function __construct(int $maximumStackSize = PHP_INT_MAX)
46
    {
47 2190
        $this->remainingDelimiters = $maximumStackSize;
48
49 2190
        if (\PHP_VERSION_ID >= 80000) {
50
            /** @psalm-suppress PropertyTypeCoercion */
51 2190
            $this->missingIndexCache = new \WeakMap(); // @phpstan-ignore-line
0 ignored issues
show
Documentation Bug introduced by
It seems like new WeakMap() of type WeakMap is incompatible with the declared type SplObjectStorage of property $missingIndexCache.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Deprecated Code introduced by
The property League\CommonMark\Delimi...ack::$missingIndexCache has been deprecated: This property will be removed in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

51
            /** @scrutinizer ignore-deprecated */ $this->missingIndexCache = new \WeakMap(); // @phpstan-ignore-line

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
52
        } else {
53
            $this->missingIndexCache = new \SplObjectStorage(); // @phpstan-ignore-line
0 ignored issues
show
Deprecated Code introduced by
The property League\CommonMark\Delimi...ack::$missingIndexCache has been deprecated: This property will be removed in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

53
            /** @scrutinizer ignore-deprecated */ $this->missingIndexCache = new \SplObjectStorage(); // @phpstan-ignore-line

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
54
        }
55
    }
56
57 632
    public function push(DelimiterInterface $newDelimiter): void
58
    {
59 632
        if ($this->remainingDelimiters-- <= 0) {
60 16
            return;
61
        }
62
63 630
        $newDelimiter->setPrevious($this->top);
64
65 630
        if ($this->top !== null) {
66 534
            $this->top->setNext($newDelimiter);
67
        }
68
69 630
        $this->top = $newDelimiter;
70
    }
71
72
    /**
73
     * @internal
74
     */
75 418
    public function addBracket(Node $node, int $index, bool $image): void
76
    {
77 418
        if ($this->brackets !== null) {
78 42
            $this->brackets->setHasNext(true);
79
        }
80
81 418
        $this->brackets = new Bracket($node, $this->brackets, $index, $image);
82
    }
83
84
    /**
85
     * @psalm-immutable
86
     */
87 408
    public function getLastBracket(): ?Bracket
88
    {
89 408
        return $this->brackets;
90
    }
91
92 2164
    private function findEarliest(int $stackBottom): ?DelimiterInterface
93
    {
94
        // Move back to first relevant delim.
95 2164
        $delimiter   = $this->top;
96 2164
        $lastChecked = null;
97
98 2164
        while ($delimiter !== null && self::getIndex($delimiter) > $stackBottom) {
0 ignored issues
show
Bug Best Practice introduced by
The method League\CommonMark\Delimi...imiterStack::getIndex() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
        while ($delimiter !== null && self::/** @scrutinizer ignore-call */ getIndex($delimiter) > $stackBottom) {
Loading history...
Deprecated Code introduced by
The function League\CommonMark\Delimi...imiterStack::getIndex() has been deprecated: This method will be dropped in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

98
        while ($delimiter !== null && /** @scrutinizer ignore-deprecated */ self::getIndex($delimiter) > $stackBottom) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
99 614
            $lastChecked = $delimiter;
100 614
            $delimiter   = $delimiter->getPrevious();
101
        }
102
103 2164
        return $lastChecked;
104
    }
105
106
    /**
107
     * @internal
108
     */
109 418
    public function removeBracket(): void
110
    {
111 418
        if ($this->brackets === null) {
112
            return;
113
        }
114
115 418
        $this->brackets = $this->brackets->getPrevious();
116
117 418
        if ($this->brackets !== null) {
118 42
            $this->brackets->setHasNext(false);
119
        }
120
    }
121
122 630
    public function removeDelimiter(DelimiterInterface $delimiter): void
123
    {
124 630
        if ($delimiter->getPrevious() !== null) {
125
            /** @psalm-suppress PossiblyNullReference */
126 236
            $delimiter->getPrevious()->setNext($delimiter->getNext());
127
        }
128
129 630
        if ($delimiter->getNext() === null) {
130
            // top of stack
131 630
            $this->top = $delimiter->getPrevious();
132
        } else {
133
            /** @psalm-suppress PossiblyNullReference */
134 466
            $delimiter->getNext()->setPrevious($delimiter->getPrevious());
135
        }
136
137
        // Nullify all references from the removed delimiter to other delimiters.
138
        // All references to this particular delimiter in the linked list should be gone,
139
        // but it's possible we're still hanging on to other references to things that
140
        // have been (or soon will be) removed, which may interfere with efficient
141
        // garbage collection by the PHP runtime.
142
        // Explicitly releasing these references should help to avoid possible
143
        // segfaults like in https://bugs.php.net/bug.php?id=68606.
144 630
        $delimiter->setPrevious(null);
145 630
        $delimiter->setNext(null);
146
147
        // TODO: Remove the line below once PHP 7.4 support is dropped, as WeakMap won't hold onto the reference, making this unnecessary
148 630
        unset($this->missingIndexCache[$delimiter]);
0 ignored issues
show
Deprecated Code introduced by
The property League\CommonMark\Delimi...ack::$missingIndexCache has been deprecated: This property will be removed in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

148
        unset(/** @scrutinizer ignore-deprecated */ $this->missingIndexCache[$delimiter]);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
149
    }
150
151 466
    private function removeDelimiterAndNode(DelimiterInterface $delimiter): void
152
    {
153 466
        $delimiter->getInlineNode()->detach();
154 466
        $this->removeDelimiter($delimiter);
155
    }
156
157 468
    private function removeDelimitersBetween(DelimiterInterface $opener, DelimiterInterface $closer): void
158
    {
159 468
        $delimiter      = $closer->getPrevious();
160 468
        $openerPosition = self::getIndex($opener);
0 ignored issues
show
Deprecated Code introduced by
The function League\CommonMark\Delimi...imiterStack::getIndex() has been deprecated: This method will be dropped in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

160
        $openerPosition = /** @scrutinizer ignore-deprecated */ self::getIndex($opener);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug Best Practice introduced by
The method League\CommonMark\Delimi...imiterStack::getIndex() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

160
        /** @scrutinizer ignore-call */ 
161
        $openerPosition = self::getIndex($opener);
Loading history...
161 468
        while ($delimiter !== null && self::getIndex($delimiter) > $openerPosition) {
0 ignored issues
show
Deprecated Code introduced by
The function League\CommonMark\Delimi...imiterStack::getIndex() has been deprecated: This method will be dropped in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

161
        while ($delimiter !== null && /** @scrutinizer ignore-deprecated */ self::getIndex($delimiter) > $openerPosition) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
162 46
            $previous = $delimiter->getPrevious();
163 46
            $this->removeDelimiter($delimiter);
164 46
            $delimiter = $previous;
165
        }
166
    }
167
168
    /**
169
     * @param DelimiterInterface|int|null $stackBottom
170
     */
171 2166
    public function removeAll($stackBottom = null): void
172
    {
173 2166
        $stackBottomPosition = \is_int($stackBottom) ? $stackBottom : self::getIndex($stackBottom);
0 ignored issues
show
Bug Best Practice introduced by
The method League\CommonMark\Delimi...imiterStack::getIndex() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
        $stackBottomPosition = \is_int($stackBottom) ? $stackBottom : self::/** @scrutinizer ignore-call */ getIndex($stackBottom);
Loading history...
Deprecated Code introduced by
The function League\CommonMark\Delimi...imiterStack::getIndex() has been deprecated: This method will be dropped in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

173
        $stackBottomPosition = \is_int($stackBottom) ? $stackBottom : /** @scrutinizer ignore-deprecated */ self::getIndex($stackBottom);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
174
175 2166
        while ($this->top && $this->getIndex($this->top) > $stackBottomPosition) {
0 ignored issues
show
Deprecated Code introduced by
The function League\CommonMark\Delimi...imiterStack::getIndex() has been deprecated: This method will be dropped in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

175
        while ($this->top && /** @scrutinizer ignore-deprecated */ $this->getIndex($this->top) > $stackBottomPosition) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
176 148
            $this->removeDelimiter($this->top);
177
        }
178
    }
179
180
    /**
181
     * @deprecated This method is no longer used internally and will be removed in 3.0
182
     */
183 2
    public function removeEarlierMatches(string $character): void
184
    {
185 2
        $opener = $this->top;
186 2
        while ($opener !== null) {
187 2
            if ($opener->getChar() === $character) {
188 2
                $opener->setActive(false);
0 ignored issues
show
Deprecated Code introduced by
The function League\CommonMark\Delimi...rInterface::setActive() has been deprecated: This method is no longer used internally and will be removed in 3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

188
                /** @scrutinizer ignore-deprecated */ $opener->setActive(false);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
189
            }
190
191 2
            $opener = $opener->getPrevious();
192
        }
193
    }
194
195
    /**
196
     * @internal
197
     */
198 280
    public function deactivateLinkOpeners(): void
199
    {
200 280
        $opener = $this->brackets;
201 280
        while ($opener !== null && $opener->isActive()) {
202 20
            $opener->setActive(false);
203 20
            $opener = $opener->getPrevious();
204
        }
205
    }
206
207
    /**
208
     * @deprecated This method is no longer used internally and will be removed in 3.0
209
     *
210
     * @param string|string[] $characters
211
     */
212 6
    public function searchByCharacter($characters): ?DelimiterInterface
213
    {
214 6
        if (! \is_array($characters)) {
215 6
            $characters = [$characters];
216
        }
217
218 6
        $opener = $this->top;
219 6
        while ($opener !== null) {
220 4
            if (\in_array($opener->getChar(), $characters, true)) {
221 4
                break;
222
            }
223
224 4
            $opener = $opener->getPrevious();
225
        }
226
227 6
        return $opener;
228
    }
229
230
    /**
231
     * @param DelimiterInterface|int|null $stackBottom
232
     *
233
     * @todo change $stackBottom to an int in 3.0
234
     */
235 2162
    public function processDelimiters($stackBottom, DelimiterProcessorCollection $processors): void
236
    {
237
        /** @var array<string, int> $openersBottom */
238 2162
        $openersBottom = [];
239
240 2162
        $stackBottomPosition = \is_int($stackBottom) ? $stackBottom : self::getIndex($stackBottom);
0 ignored issues
show
Deprecated Code introduced by
The function League\CommonMark\Delimi...imiterStack::getIndex() has been deprecated: This method will be dropped in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

240
        $stackBottomPosition = \is_int($stackBottom) ? $stackBottom : /** @scrutinizer ignore-deprecated */ self::getIndex($stackBottom);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug Best Practice introduced by
The method League\CommonMark\Delimi...imiterStack::getIndex() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

240
        $stackBottomPosition = \is_int($stackBottom) ? $stackBottom : self::/** @scrutinizer ignore-call */ getIndex($stackBottom);
Loading history...
241
242
        // Find first closer above stackBottom
243 2162
        $closer = $this->findEarliest($stackBottomPosition);
244
245
        // Move forward, looking for closers, and handling each
246 2162
        while ($closer !== null) {
247 612
            $closingDelimiterChar = $closer->getChar();
248
249 612
            $delimiterProcessor = $processors->getDelimiterProcessor($closingDelimiterChar);
250 612
            if (! $closer->canClose() || $delimiterProcessor === null) {
251 546
                $closer = $closer->getNext();
252 546
                continue;
253
            }
254
255 554
            if ($delimiterProcessor instanceof CacheableDelimiterProcessorInterface) {
256 460
                $openersBottomCacheKey = $delimiterProcessor->getCacheKey($closer);
257
            } else {
258 98
                $openersBottomCacheKey = $closingDelimiterChar;
259
            }
260
261 554
            $openingDelimiterChar = $delimiterProcessor->getOpeningCharacter();
262
263 554
            $useDelims            = 0;
264 554
            $openerFound          = false;
265 554
            $potentialOpenerFound = false;
266 554
            $opener               = $closer->getPrevious();
267 554
            while ($opener !== null && ($openerPosition = self::getIndex($opener)) > $stackBottomPosition && $openerPosition >= ($openersBottom[$openersBottomCacheKey] ?? 0)) {
0 ignored issues
show
Deprecated Code introduced by
The function League\CommonMark\Delimi...imiterStack::getIndex() has been deprecated: This method will be dropped in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

267
            while ($opener !== null && ($openerPosition = /** @scrutinizer ignore-deprecated */ self::getIndex($opener)) > $stackBottomPosition && $openerPosition >= ($openersBottom[$openersBottomCacheKey] ?? 0)) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
268 486
                if ($opener->canOpen() && $opener->getChar() === $openingDelimiterChar) {
269 484
                    $potentialOpenerFound = true;
270 484
                    $useDelims            = $delimiterProcessor->getDelimiterUse($opener, $closer);
271 484
                    if ($useDelims > 0) {
272 466
                        $openerFound = true;
273 466
                        break;
274
                    }
275
                }
276
277 78
                $opener = $opener->getPrevious();
278
            }
279
280 554
            if (! $openerFound) {
281
                // Set lower bound for future searches
282
                // TODO: Remove this conditional check in 3.0. It only exists to prevent behavioral BC breaks in 2.x.
283 182
                if ($potentialOpenerFound === false || $delimiterProcessor instanceof CacheableDelimiterProcessorInterface) {
284 164
                    $openersBottom[$openersBottomCacheKey] = self::getIndex($closer);
0 ignored issues
show
Deprecated Code introduced by
The function League\CommonMark\Delimi...imiterStack::getIndex() has been deprecated: This method will be dropped in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

284
                    $openersBottom[$openersBottomCacheKey] = /** @scrutinizer ignore-deprecated */ self::getIndex($closer);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
285
                }
286
287 182
                if (! $potentialOpenerFound && ! $closer->canOpen()) {
288
                    // We can remove a closer that can't be an opener,
289
                    // once we've seen there's no matching opener.
290 100
                    $next = $closer->getNext();
291 100
                    $this->removeDelimiter($closer);
292 100
                    $closer = $next;
293
                } else {
294 86
                    $closer = $closer->getNext();
295
                }
296
297 182
                continue;
298
            }
299
300
            \assert($opener !== null);
301
302 466
            $openerNode = $opener->getInlineNode();
303 466
            $closerNode = $closer->getInlineNode();
304
305
            // Remove number of used delimiters from stack and inline nodes.
306 466
            $opener->setLength($opener->getLength() - $useDelims);
307 466
            $closer->setLength($closer->getLength() - $useDelims);
308
309 466
            $openerNode->setLiteral(\substr($openerNode->getLiteral(), 0, -$useDelims));
310 466
            $closerNode->setLiteral(\substr($closerNode->getLiteral(), 0, -$useDelims));
311
312 466
            $this->removeDelimitersBetween($opener, $closer);
313
            // The delimiter processor can re-parent the nodes between opener and closer,
314
            // so make sure they're contiguous already. Exclusive because we want to keep opener/closer themselves.
315 466
            AdjacentTextMerger::mergeTextNodesBetweenExclusive($openerNode, $closerNode);
316 466
            $delimiterProcessor->process($openerNode, $closerNode, $useDelims);
317
318
            // No delimiter characters left to process, so we can remove delimiter and the now empty node.
319 466
            if ($opener->getLength() === 0) {
320 448
                $this->removeDelimiterAndNode($opener);
321
            }
322
323
            // phpcs:disable SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed
324 466
            if ($closer->getLength() === 0) {
325 450
                $next = $closer->getNext();
326 450
                $this->removeDelimiterAndNode($closer);
327 450
                $closer = $next;
328
            }
329
        }
330
331
        // Remove all delimiters
332 2162
        $this->removeAll($stackBottomPosition);
333
    }
334
335
    /**
336
     * @internal
337
     */
338 2190
    public function __destruct()
339
    {
340 2190
        while ($this->top) {
341 16
            $this->removeDelimiter($this->top);
342
        }
343
344 2190
        while ($this->brackets) {
345 28
            $this->removeBracket();
346
        }
347
    }
348
349
    /**
350
     * @deprecated This method will be dropped in 3.0 once all delimiters MUST have an index/position
351
     */
352 2172
    private function getIndex(?DelimiterInterface $delimiter): int
353
    {
354 2172
        if ($delimiter === null) {
355 2166
            return -1;
356
        }
357
358 622
        if (($index = $delimiter->getIndex()) !== null) {
359 618
            return $index;
360
        }
361
362 6
        if (isset($this->missingIndexCache[$delimiter])) {
0 ignored issues
show
Deprecated Code introduced by
The property League\CommonMark\Delimi...ack::$missingIndexCache has been deprecated: This property will be removed in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

362
        if (isset(/** @scrutinizer ignore-deprecated */ $this->missingIndexCache[$delimiter])) {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
363 4
            return $this->missingIndexCache[$delimiter];
364
        }
365
366 6
        $prev = $delimiter->getPrevious();
367 6
        $next = $delimiter->getNext();
368
369 6
        $i = 0;
370
        do {
371 6
            $i++;
372 6
            if ($prev === null) {
373 6
                break;
374
            }
375
376 6
            if ($prev->getIndex() !== null) {
377 2
                return $this->missingIndexCache[$delimiter] = $prev->getIndex() + $i;
0 ignored issues
show
Deprecated Code introduced by
The property League\CommonMark\Delimi...ack::$missingIndexCache has been deprecated: This property will be removed in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

377
                return /** @scrutinizer ignore-deprecated */ $this->missingIndexCache[$delimiter] = $prev->getIndex() + $i;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
378
            }
379 6
        } while ($prev = $prev->getPrevious());
380
381 6
        $j = 0;
382
        do {
383 6
            $j++;
384 6
            if ($next === null) {
385 4
                break;
386
            }
387
388 6
            if ($next->getIndex() !== null) {
389 2
                return $this->missingIndexCache[$delimiter] = $next->getIndex() - $j;
0 ignored issues
show
Deprecated Code introduced by
The property League\CommonMark\Delimi...ack::$missingIndexCache has been deprecated: This property will be removed in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

389
                return /** @scrutinizer ignore-deprecated */ $this->missingIndexCache[$delimiter] = $next->getIndex() - $j;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
390
            }
391 4
        } while ($next = $next->getNext());
392
393
        // No index was defined on this delimiter, and none could be guesstimated based on the stack.
394 4
        return $this->missingIndexCache[$delimiter] = $this->getIndex($delimiter->getPrevious()) + 1;
0 ignored issues
show
Deprecated Code introduced by
The property League\CommonMark\Delimi...ack::$missingIndexCache has been deprecated: This property will be removed in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

394
        return /** @scrutinizer ignore-deprecated */ $this->missingIndexCache[$delimiter] = $this->getIndex($delimiter->getPrevious()) + 1;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The function League\CommonMark\Delimi...imiterStack::getIndex() has been deprecated: This method will be dropped in 3.0 once all delimiters MUST have an index/position ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

394
        return $this->missingIndexCache[$delimiter] = /** @scrutinizer ignore-deprecated */ $this->getIndex($delimiter->getPrevious()) + 1;

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
395
    }
396
}
397