DelimiterStack   F
last analyzed

Complexity

Total Complexity 67

Size/Duplication

Total Lines 368
Duplicated Lines 0 %

Test Coverage

Coverage 98.7%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 150
c 2
b 0
f 0
dl 0
loc 368
ccs 152
cts 154
cp 0.987
rs 3.04
wmc 67

16 Methods

Rating   Name   Duplication   Size   Complexity  
A removeEarlierMatches() 0 9 3
D processDelimiters() 0 98 19
B getIndex() 0 43 10
A removeDelimiterAndNode() 0 4 1
A deactivateLinkOpeners() 0 6 3
A getLastBracket() 0 3 1
A searchByCharacter() 0 16 4
A removeAll() 0 6 4
A removeDelimitersBetween() 0 8 3
A removeBracket() 0 10 3
A __destruct() 0 8 3
A findEarliest() 0 12 3
A addBracket() 0 7 2
A push() 0 13 3
A __construct() 0 9 2
A removeDelimiter() 0 27 3

How to fix   Complexity   

Complex Class

Complex classes like DelimiterStack often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use DelimiterStack, and based on these observations, apply Extract Interface, too.

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 2124
    public function __construct(int $maximumStackSize = PHP_INT_MAX)
46
    {
47 2124
        $this->remainingDelimiters = $maximumStackSize;
48
49 2124
        if (\PHP_VERSION_ID >= 80000) {
50
            /** @psalm-suppress PropertyTypeCoercion */
51 2124
            $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 578
    public function push(DelimiterInterface $newDelimiter): void
58
    {
59 578
        if ($this->remainingDelimiters-- <= 0) {
60 16
            return;
61
        }
62
63 576
        $newDelimiter->setPrevious($this->top);
64
65 576
        if ($this->top !== null) {
66 488
            $this->top->setNext($newDelimiter);
67
        }
68
69 576
        $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 2098
    private function findEarliest(int $stackBottom): ?DelimiterInterface
93
    {
94
        // Move back to first relevant delim.
95 2098
        $delimiter   = $this->top;
96 2098
        $lastChecked = null;
97
98 2098
        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 560
            $lastChecked = $delimiter;
100 560
            $delimiter   = $delimiter->getPrevious();
101
        }
102
103 2098
        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 576
    public function removeDelimiter(DelimiterInterface $delimiter): void
123
    {
124 576
        if ($delimiter->getPrevious() !== null) {
125
            /** @psalm-suppress PossiblyNullReference */
126 214
            $delimiter->getPrevious()->setNext($delimiter->getNext());
127
        }
128
129 576
        if ($delimiter->getNext() === null) {
130
            // top of stack
131 576
            $this->top = $delimiter->getPrevious();
132
        } else {
133
            /** @psalm-suppress PossiblyNullReference */
134 426
            $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 576
        $delimiter->setPrevious(null);
145 576
        $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 576
        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 426
    private function removeDelimiterAndNode(DelimiterInterface $delimiter): void
152
    {
153 426
        $delimiter->getInlineNode()->detach();
154 426
        $this->removeDelimiter($delimiter);
155
    }
156
157 428
    private function removeDelimitersBetween(DelimiterInterface $opener, DelimiterInterface $closer): void
158
    {
159 428
        $delimiter      = $closer->getPrevious();
160 428
        $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 428
        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 34
            $previous = $delimiter->getPrevious();
163 34
            $this->removeDelimiter($delimiter);
164 34
            $delimiter = $previous;
165
        }
166
    }
167
168
    /**
169
     * @param DelimiterInterface|int|null $stackBottom
170
     */
171 2100
    public function removeAll($stackBottom = null): void
172
    {
173 2100
        $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 2100
        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 136
            $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 2096
    public function processDelimiters($stackBottom, DelimiterProcessorCollection $processors): void
236
    {
237
        /** @var array<string, int> $openersBottom */
238 2096
        $openersBottom = [];
239
240 2096
        $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 2096
        $closer = $this->findEarliest($stackBottomPosition);
244
245
        // Move forward, looking for closers, and handling each
246 2096
        while ($closer !== null) {
247 558
            $closingDelimiterChar = $closer->getChar();
248
249 558
            $delimiterProcessor = $processors->getDelimiterProcessor($closingDelimiterChar);
250 558
            if (! $closer->canClose() || $delimiterProcessor === null) {
251 494
                $closer = $closer->getNext();
252 494
                continue;
253
            }
254
255 504
            if ($delimiterProcessor instanceof CacheableDelimiterProcessorInterface) {
256 456
                $openersBottomCacheKey = $delimiterProcessor->getCacheKey($closer);
257
            } else {
258 48
                $openersBottomCacheKey = $closingDelimiterChar;
259
            }
260
261 504
            $openingDelimiterChar = $delimiterProcessor->getOpeningCharacter();
262
263 504
            $useDelims            = 0;
264 504
            $openerFound          = false;
265 504
            $potentialOpenerFound = false;
266 504
            $opener               = $closer->getPrevious();
267 504
            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 440
                if ($opener->canOpen() && $opener->getChar() === $openingDelimiterChar) {
269 438
                    $potentialOpenerFound = true;
270 438
                    $useDelims            = $delimiterProcessor->getDelimiterUse($opener, $closer);
271 438
                    if ($useDelims > 0) {
272 426
                        $openerFound = true;
273 426
                        break;
274
                    }
275
                }
276
277 60
                $opener = $opener->getPrevious();
278
            }
279
280 504
            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 158
                if ($potentialOpenerFound === false || $delimiterProcessor instanceof CacheableDelimiterProcessorInterface) {
284 156
                    $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 158
                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 92
                    $next = $closer->getNext();
291 92
                    $this->removeDelimiter($closer);
292 92
                    $closer = $next;
293
                } else {
294 70
                    $closer = $closer->getNext();
295
                }
296
297 158
                continue;
298
            }
299
300
            \assert($opener !== null);
301
302 426
            $openerNode = $opener->getInlineNode();
303 426
            $closerNode = $closer->getInlineNode();
304
305
            // Remove number of used delimiters from stack and inline nodes.
306 426
            $opener->setLength($opener->getLength() - $useDelims);
307 426
            $closer->setLength($closer->getLength() - $useDelims);
308
309 426
            $openerNode->setLiteral(\substr($openerNode->getLiteral(), 0, -$useDelims));
310 426
            $closerNode->setLiteral(\substr($closerNode->getLiteral(), 0, -$useDelims));
311
312 426
            $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 426
            AdjacentTextMerger::mergeTextNodesBetweenExclusive($openerNode, $closerNode);
316 426
            $delimiterProcessor->process($openerNode, $closerNode, $useDelims);
317
318
            // No delimiter characters left to process, so we can remove delimiter and the now empty node.
319 426
            if ($opener->getLength() === 0) {
320 408
                $this->removeDelimiterAndNode($opener);
321
            }
322
323
            // phpcs:disable SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed
324 426
            if ($closer->getLength() === 0) {
325 410
                $next = $closer->getNext();
326 410
                $this->removeDelimiterAndNode($closer);
327 410
                $closer = $next;
328
            }
329
        }
330
331
        // Remove all delimiters
332 2096
        $this->removeAll($stackBottomPosition);
333
    }
334
335
    /**
336
     * @internal
337
     */
338 2124
    public function __destruct()
339
    {
340 2124
        while ($this->top) {
341 16
            $this->removeDelimiter($this->top);
342
        }
343
344 2124
        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 2106
    private function getIndex(?DelimiterInterface $delimiter): int
353
    {
354 2106
        if ($delimiter === null) {
355 2100
            return -1;
356
        }
357
358 568
        if (($index = $delimiter->getIndex()) !== null) {
359 564
            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