Skip to content
Permalink
Browse files

Merge pull request #368 from thephpleague/delimiter

Standardize delimiter processing node types
  • Loading branch information...
colinodell committed May 27, 2019
2 parents 9026ddb + f748e45 commit ccfcc72cff98ca70e006df32d7968c3c683f34fe
@@ -4,6 +4,11 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi

## [Unreleased][unreleased]

### Changed

- `DelimiterProcessorInterface::process()` will accept any type of `AbstractStringContainer` now, not just `Text` nodes
- The `Delimiter` constructor, `getInlineNode()`, and `setInlineNode()` no longer accept generic `Node` elements - only `AbstractStringContainer`s

## [1.0.0-beta1] - 2019-05-26

### Added
@@ -2,6 +2,12 @@

**Note:** This file has been deprecated. Future upgrade instructions can be found on our website: <https://commonmark.thephpleague.com/releases>

## UNRELEASED

### Delimiter Processing

We've standardized the new delimiter processing to work with `AbstractStringContainer` nodes. Previously in 1.0.0-beta1, some parts (incorrectly) accepted any type of `Node`, while others forced you to use `Text` elements instead.

## 1.0.0-beta1

### Text Encoding
@@ -14,7 +14,7 @@
namespace League\CommonMark\Delimiter;
use League\CommonMark\Node\Node;
use League\CommonMark\Inline\Element\AbstractStringContainer;
class Delimiter
{
@@ -27,7 +27,7 @@ class Delimiter
/** @var int */
protected $origDelims;
/** @var Node */
/** @var AbstractStringContainer */
protected $inlineNode;
/** @var Delimiter|null */
@@ -49,14 +49,14 @@ class Delimiter
protected $index;
/**
* @param string $char
* @param int $numDelims
* @param Node $node
* @param bool $canOpen
* @param bool $canClose
* @param int|null $index
* @param string $char
* @param int $numDelims
* @param AbstractStringContainer $node
* @param bool $canOpen
* @param bool $canClose
* @param int|null $index
*/
public function __construct(string $char, int $numDelims, Node $node, bool $canOpen, bool $canClose, ?int $index = null)
public function __construct(string $char, int $numDelims, AbstractStringContainer $node, bool $canOpen, bool $canClose, ?int $index = null)
{
$this->char = $char;
$this->numDelims = $numDelims;
@@ -217,19 +217,19 @@ public function getOrigDelims(): int
}
/**
* @return Node
* @return AbstractStringContainer
*/
public function getInlineNode(): Node
public function getInlineNode(): AbstractStringContainer
{
return $this->inlineNode;
}
/**
* @param Node $node
* @param AbstractStringContainer $node
*
* @return $this
*/
public function setInlineNode(Node $node)
public function setInlineNode(AbstractStringContainer $node)
{
$this->inlineNode = $node;
@@ -19,7 +19,6 @@
use League\CommonMark\Delimiter\Processor\DelimiterProcessorCollection;
use League\CommonMark\Inline\AdjacentTextMerger;
use League\CommonMark\Inline\Element\Text;
class DelimiterStack
{
@@ -189,9 +188,7 @@ public function processDelimiters(?Delimiter $stackBottom, DelimiterProcessorCol
continue;
}
/** @var Text $openerNode */
$openerNode = $opener->getInlineNode();
/** @var Text $closerNode */
$closerNode = $closer->getInlineNode();
// Remove number of used delimiters from stack and inline nodes.
@@ -18,7 +18,7 @@
namespace League\CommonMark\Delimiter\Processor;
use League\CommonMark\Delimiter\Delimiter;
use League\CommonMark\Inline\Element\Text;
use League\CommonMark\Inline\Element\AbstractStringContainer;
/**
* Interface for a delimiter processor
@@ -76,9 +76,9 @@ public function getDelimiterUse(Delimiter $opener, Delimiter $closer): int;
* Note that removal of the delimiter from the delimiter nodes and detaching
* them is done by the caller.
*
* @param Text $opener The Text node that contained the opening delimiter
* @param Text $closer The text node that contained the closing delimiter
* @param int $delimiterUse The number of delimiters that were used
* @param AbstractStringContainer $opener The node that contained the opening delimiter
* @param AbstractStringContainer $closer The node that contained the closing delimiter
* @param int $delimiterUse The number of delimiters that were used
*/
public function process(Text $opener, Text $closer, int $delimiterUse);
public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse);
}
@@ -18,9 +18,9 @@
namespace League\CommonMark\Delimiter\Processor;
use League\CommonMark\Delimiter\Delimiter;
use League\CommonMark\Inline\Element\AbstractStringContainer;
use League\CommonMark\Inline\Element\Emphasis;
use League\CommonMark\Inline\Element\Strong;
use League\CommonMark\Inline\Element\Text;
use League\CommonMark\Util\ConfigurationAwareInterface;
use League\CommonMark\Util\ConfigurationInterface;
@@ -93,7 +93,7 @@ public function getDelimiterUse(Delimiter $opener, Delimiter $closer): int
/**
* {@inheritdoc}
*/
public function process(Text $opener, Text $closer, int $delimiterUse)
public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse)
{
if ($delimiterUse === 1) {
$emphasis = new Emphasis();
@@ -15,7 +15,7 @@
namespace League\CommonMark\Delimiter\Processor;
use League\CommonMark\Delimiter\Delimiter;
use League\CommonMark\Inline\Element\Text;
use League\CommonMark\Inline\Element\AbstractStringContainer;
/**
* An implementation of DelimiterProcessorInterface that dispatches all calls to two or more other DelimiterProcessors
@@ -92,7 +92,7 @@ public function getDelimiterUse(Delimiter $opener, Delimiter $closer): int
/**
* {@inheritdoc}
*/
public function process(Text $opener, Text $closer, int $delimiterUse)
public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse)
{
return $this->findProcessor($delimiterUse)->process($opener, $closer, $delimiterUse);
}
@@ -16,7 +16,7 @@
use League\CommonMark\Delimiter\Delimiter;
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
use League\CommonMark\Inline\Element\Text;
use League\CommonMark\Inline\Element\AbstractStringContainer;
final class FakeDelimiterProcessor implements DelimiterProcessorInterface
{
@@ -65,7 +65,7 @@ public function getDelimiterUse(Delimiter $opener, Delimiter $closer): int
/**
* {@inheritdoc}
*/
public function process(Text $opener, Text $closer, int $delimiterUse)
public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse)
{
}
}
@@ -16,6 +16,7 @@
use League\CommonMark\Delimiter\Delimiter;
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
use League\CommonMark\Inline\Element\AbstractStringContainer;
use League\CommonMark\Inline\Element\Text;
final class TestDelimiterProcessor implements DelimiterProcessorInterface
@@ -64,7 +65,7 @@ public function getDelimiterUse(Delimiter $opener, Delimiter $closer): int
/**
* {@inheritdoc}
*/
public function process(Text $opener, Text $closer, int $delimiterUse)
public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse)
{
$opener->insertAfter(new Text('(' . $this->length . ')'));
$closer->insertBefore(new Text('(/' . $this->length . ')'));
@@ -16,7 +16,7 @@
use League\CommonMark\Delimiter\Delimiter;
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
use League\CommonMark\Inline\Element\Text;
use League\CommonMark\Inline\Element\AbstractStringContainer;
final class UppercaseDelimiterProcessor implements DelimiterProcessorInterface
{
@@ -55,7 +55,7 @@ public function getDelimiterUse(Delimiter $opener, Delimiter $closer): int
/**
* {@inheritdoc}
*/
public function process(Text $opener, Text $closer, int $delimiterUse)
public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse)
{
$upperCase = new UppercaseText();
$tmp = $opener->next();
@@ -12,14 +12,14 @@
namespace League\CommonMark\Tests\Unit\Delimiter;
use League\CommonMark\Delimiter\Delimiter;
use League\CommonMark\Node\Node;
use League\CommonMark\Inline\Element\AbstractStringContainer;
use PHPUnit\Framework\TestCase;
class DelimiterTest extends TestCase
{
public function testConstructorAndGetters()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$this->assertSame('*', $delimiter->getChar());
@@ -42,7 +42,7 @@ public function testConstructorAndGetters()
public function testSetCanClose()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$delimiter->setCanClose(true);
@@ -51,7 +51,7 @@ public function testSetCanClose()
public function testSetCanOpen()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$delimiter->setCanOpen(false);
@@ -60,7 +60,7 @@ public function testSetCanOpen()
public function testSetActive()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$delimiter->setActive(true);
@@ -72,7 +72,7 @@ public function testSetActive()
public function testSetChar()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$delimiter->setChar('_');
@@ -81,7 +81,7 @@ public function testSetChar()
public function testSetIndex()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$delimiter->setIndex(7);
@@ -93,7 +93,7 @@ public function testSetIndex()
public function testSetNext()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$delimiter->setNext($delimiter);
@@ -105,7 +105,7 @@ public function testSetNext()
public function testSetNumDelims()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$delimiter->setNumDelims(3);
@@ -115,18 +115,18 @@ public function testSetNumDelims()
public function testSetInlineNode()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$node2 = $this->createMock(Node::class);
$node2 = $this->createMock(AbstractStringContainer::class);
$delimiter->setInlineNode($node2);
$this->assertSame($node2, $delimiter->getInlineNode());
}
public function testSetPrevious()
{
$node = $this->createMock(Node::class);
$node = $this->createMock(AbstractStringContainer::class);
$delimiter = new Delimiter('*', 2, $node, true, false, null);
$delimiter->setPrevious($delimiter);

0 comments on commit ccfcc72

Please sign in to comment.
You can’t perform that action at this time.