diff --git a/src/Delimiter/DelimiterStack.php b/src/Delimiter/DelimiterStack.php index 25003f942d..665b03799e 100644 --- a/src/Delimiter/DelimiterStack.php +++ b/src/Delimiter/DelimiterStack.php @@ -21,7 +21,6 @@ use League\CommonMark\Delimiter\Processor\CacheableDelimiterProcessorInterface; use League\CommonMark\Delimiter\Processor\DelimiterProcessorCollection; -use League\CommonMark\Exception\LogicException; use League\CommonMark\Node\Inline\AdjacentTextMerger; use League\CommonMark\Node\Node; @@ -81,9 +80,6 @@ public function getLastBracket(): ?Bracket return $this->brackets; } - /** - * @throws LogicException - */ private function findEarliest(int $stackBottom): ?DelimiterInterface { // Move back to first relevant delim. @@ -149,9 +145,6 @@ private function removeDelimiterAndNode(DelimiterInterface $delimiter): void $this->removeDelimiter($delimiter); } - /** - * @throws LogicException - */ private function removeDelimitersBetween(DelimiterInterface $opener, DelimiterInterface $closer): void { $delimiter = $closer->getPrevious(); @@ -165,8 +158,6 @@ private function removeDelimitersBetween(DelimiterInterface $opener, DelimiterIn /** * @param DelimiterInterface|int|null $stackBottom - * - * @throws LogicException if the index/position cannot be determined for some delimiter */ public function removeAll($stackBottom = null): void { @@ -230,8 +221,6 @@ public function searchByCharacter($characters): ?DelimiterInterface /** * @param DelimiterInterface|int|null $stackBottom * - * @throws LogicException if the index/position cannot be determined for any delimiter - * * @todo change $stackBottom to an int in 3.0 */ public function processDelimiters($stackBottom, DelimiterProcessorCollection $processors): void @@ -350,8 +339,6 @@ public function __destruct() /** * @deprecated This method will be dropped in 3.0 once all delimiters MUST have an index/position - * - * @throws LogicException if no index was defined on this delimiter, and no reasonable guess could be made based on its neighbors */ private function getIndex(?DelimiterInterface $delimiter): int { @@ -395,6 +382,6 @@ private function getIndex(?DelimiterInterface $delimiter): int } while ($next = $next->getNext()); // No index was defined on this delimiter, and none could be guesstimated based on the stack. - throw new LogicException('No index was defined on this delimiter, and none could be guessed based on the stack. Ensure you are passing the index when instantiating the Delimiter.'); + return $this->missingIndexCache[$delimiter] = $this->getIndex($delimiter->getPrevious()) + 1; } } diff --git a/src/Extension/Table/TableParser.php b/src/Extension/Table/TableParser.php index c4f441d123..a005f8a97e 100644 --- a/src/Extension/Table/TableParser.php +++ b/src/Extension/Table/TableParser.php @@ -15,7 +15,6 @@ namespace League\CommonMark\Extension\Table; -use League\CommonMark\Exception\LogicException; use League\CommonMark\Parser\Block\AbstractBlockContinueParser; use League\CommonMark\Parser\Block\BlockContinue; use League\CommonMark\Parser\Block\BlockContinueParserInterface; @@ -151,9 +150,6 @@ public function parseInlines(InlineParserEngineInterface $inlineParser): void } } - /** - * @throws LogicException - */ private function parseCell(string $cell, int $column, InlineParserEngineInterface $inlineParser): TableCell { $tableCell = new TableCell(TableCell::TYPE_DATA, $this->columns[$column] ?? null); diff --git a/src/Parser/Block/BlockContinueParserWithInlinesInterface.php b/src/Parser/Block/BlockContinueParserWithInlinesInterface.php index 595b73768c..6f826c9a91 100644 --- a/src/Parser/Block/BlockContinueParserWithInlinesInterface.php +++ b/src/Parser/Block/BlockContinueParserWithInlinesInterface.php @@ -13,15 +13,12 @@ namespace League\CommonMark\Parser\Block; -use League\CommonMark\Exception\LogicException; use League\CommonMark\Parser\InlineParserEngineInterface; interface BlockContinueParserWithInlinesInterface extends BlockContinueParserInterface { /** * Parse any inlines inside of the current block - * - * @throws LogicException */ public function parseInlines(InlineParserEngineInterface $inlineParser): void; } diff --git a/src/Parser/Inline/InlineParserInterface.php b/src/Parser/Inline/InlineParserInterface.php index 322cf9849e..fd13435bcf 100644 --- a/src/Parser/Inline/InlineParserInterface.php +++ b/src/Parser/Inline/InlineParserInterface.php @@ -13,15 +13,11 @@ namespace League\CommonMark\Parser\Inline; -use League\CommonMark\Exception\LogicException; use League\CommonMark\Parser\InlineParserContext; interface InlineParserInterface { public function getMatchDefinition(): InlineParserMatch; - /** - * @throws LogicException - */ public function parse(InlineParserContext $inlineContext): bool; } diff --git a/src/Parser/InlineParserEngineInterface.php b/src/Parser/InlineParserEngineInterface.php index cb48903162..8a0986dc13 100644 --- a/src/Parser/InlineParserEngineInterface.php +++ b/src/Parser/InlineParserEngineInterface.php @@ -13,7 +13,6 @@ namespace League\CommonMark\Parser; -use League\CommonMark\Exception\LogicException; use League\CommonMark\Node\Block\AbstractBlock; /** @@ -23,8 +22,6 @@ interface InlineParserEngineInterface { /** * Parse the given contents as inlines and insert them into the given block - * - * @throws LogicException */ public function parse(string $contents, AbstractBlock $block): void; } diff --git a/src/Parser/MarkdownParser.php b/src/Parser/MarkdownParser.php index 8412a95492..904c7c45b4 100644 --- a/src/Parser/MarkdownParser.php +++ b/src/Parser/MarkdownParser.php @@ -23,7 +23,6 @@ use League\CommonMark\Event\DocumentParsedEvent; use League\CommonMark\Event\DocumentPreParsedEvent; use League\CommonMark\Exception\CommonMarkException; -use League\CommonMark\Exception\LogicException; use League\CommonMark\Input\MarkdownInput; use League\CommonMark\Node\Block\Document; use League\CommonMark\Node\Block\Paragraph; @@ -267,8 +266,6 @@ private function finalize(BlockContinueParserInterface $blockParser, int $endLin /** * Walk through a block & children recursively, parsing string content into inline content where appropriate. - * - * @throws LogicException */ private function processInlines(int $inputSize): void { diff --git a/tests/unit/Delimiter/DelimiterStackTest.php b/tests/unit/Delimiter/DelimiterStackTest.php index d3c7a25860..8c7804425e 100644 --- a/tests/unit/Delimiter/DelimiterStackTest.php +++ b/tests/unit/Delimiter/DelimiterStackTest.php @@ -345,7 +345,7 @@ public function testGetIndex(): void $method = $reflection->getMethod('getIndex'); $method->setAccessible(true); - $this->assertSame(0, $method->invoke($stack, $delim1)); + $this->assertSame(9, $method->invoke($stack, $delim1)); $this->assertSame(10, $method->invoke($stack, $delim2)); $this->assertSame(20, $method->invoke($stack, $delim3)); $this->assertSame(21, $method->invoke($stack, $delim4));