Skip to content

Commit

Permalink
[FEATURE] Make DocumentParserContext Available in Text Roles
Browse files Browse the repository at this point in the history
TextRoles might also need the DocumentParserContext
  • Loading branch information
linawolf committed Aug 12, 2023
1 parent 176b442 commit bde5c01
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function apply(DocumentParserContext $documentParserContext, InlineLexer
$fullRole = ($domain ? $domain . ':' : '') . $role;
$lexer->moveNext();

return $textRole->processNode($documentParserContext->getContext(), $fullRole, $part, $rawPart);
return $textRole->processNode($documentParserContext, $fullRole, $part, $rawPart);
}

$inText = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use phpDocumentor\Guides\Nodes\Inline\AbbreviationInlineNode;
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
use phpDocumentor\Guides\ParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
use Psr\Log\LoggerInterface;

use function preg_match;
Expand Down Expand Up @@ -34,7 +34,7 @@ public function getAliases(): array

/** @return AbbreviationInlineNode */
public function processNode(
ParserContext $parserContext,
DocumentParserContext $documentParserContext,
string $role,
string $content,
string $rawContent,
Expand All @@ -45,7 +45,7 @@ public function processNode(

$this->logger->warning(
'Abbreviation has no definition. Usage: :abbreviation:`term (some term definition)`',
$parserContext->getLoggerInformation(),
$documentParserContext->getContext()->getLoggerInformation(),
);

return new AbbreviationInlineNode($content, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace phpDocumentor\Guides\RestructuredText\TextRoles;

use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
use phpDocumentor\Guides\ParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
use Psr\Log\LoggerInterface;

Expand All @@ -25,7 +25,7 @@ public function __construct(
}

public function processNode(
ParserContext $parserContext,
DocumentParserContext $documentParserContext,
string $role,
string $content,
string $rawContent,
Expand Down Expand Up @@ -58,7 +58,7 @@ public function processNode(
'Reference contains unexpected content after closing `>`: "%s"',
$content,
),
$parserContext->getLoggerInformation(),
$documentParserContext->getContext()->getLoggerInformation(),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace phpDocumentor\Guides\RestructuredText\TextRoles;

use phpDocumentor\Guides\Nodes\Inline\GenericTextRoleInlineNode;
use phpDocumentor\Guides\ParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;

class GenericTextRole implements TextRole
{
Expand All @@ -23,7 +23,7 @@ public function getAliases(): array
}

public function processNode(
ParserContext $parserContext,
DocumentParserContext $documentParserContext,
string $role,
string $content,
string $rawContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace phpDocumentor\Guides\RestructuredText\TextRoles;

use phpDocumentor\Guides\Nodes\Inline\GenericTextRoleInlineNode;
use phpDocumentor\Guides\ParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;

class LiteralTextRole implements TextRole
{
Expand All @@ -23,7 +23,7 @@ public function getAliases(): array
}

public function processNode(
ParserContext $parserContext,
DocumentParserContext $documentParserContext,
string $role,
string $content,
string $rawContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace phpDocumentor\Guides\RestructuredText\TextRoles;

use phpDocumentor\Guides\Nodes\Inline\GenericTextRoleInlineNode;
use phpDocumentor\Guides\ParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;

class MathTextRole implements TextRole
{
Expand All @@ -23,7 +23,7 @@ public function getAliases(): array
}

public function processNode(
ParserContext $parserContext,
DocumentParserContext $documentParserContext,
string $role,
string $content,
string $rawContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace phpDocumentor\Guides\RestructuredText\TextRoles;

use phpDocumentor\Guides\Nodes\Inline\InlineNode;
use phpDocumentor\Guides\ParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;

interface TextRole
{
Expand All @@ -19,7 +19,7 @@ public function getAliases(): array;
* @param string $rawContent the raw content, including backslash escapes
*/
public function processNode(
ParserContext $parserContext,
DocumentParserContext $documentParserContext,
string $role,
string $content,
string $rawContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Generator;
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
use phpDocumentor\Guides\ParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
use phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules\TextRoleRule;
Expand Down Expand Up @@ -65,7 +64,7 @@ public function getAliases(): array
return [];
}

public function processNode(ParserContext $parserContext, string $role, string $content, string $rawContent): InlineNode
public function processNode(DocumentParserContext $documentParserContext, string $role, string $content, string $rawContent): InlineNode
{
return new class ($role, $content, $rawContent) extends InlineNode {
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Monolog\Logger;
use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
use phpDocumentor\Guides\ParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand All @@ -15,12 +15,12 @@ class DocReferenceTextRoleTest extends TestCase
{
private Logger $logger;
private DocReferenceTextRole $docReferenceTextRole;
private ParserContext&MockObject $parserContext;
private DocumentParserContext&MockObject $documentParserContext;

public function setUp(): void
{
$this->logger = new Logger('test');
$this->parserContext = $this->createMock(ParserContext::class);
$this->documentParserContext = $this->createMock(DocumentParserContext::class);
$this->docReferenceTextRole = new DocReferenceTextRole($this->logger);
}

Expand All @@ -30,7 +30,7 @@ public function testDocReferenceIsParsedIntoDocReferenceNode(
string $url,
string|null $text = null,
): void {
$result = $this->docReferenceTextRole->processNode($this->parserContext, 'doc', $span, $span);
$result = $this->docReferenceTextRole->processNode($this->documentParserContext, 'doc', $span, $span);

self::assertInstanceOf(DocReferenceNode::class, $result);
self::assertEquals($url, $result->getTargetReference(), 'DocumentLinks are different');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Monolog\Logger;
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
use phpDocumentor\Guides\ParserContext;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand All @@ -15,12 +15,12 @@ class ReferenceTextRoleTest extends TestCase
{
private Logger $logger;
private ReferenceTextRole $referenceTextRole;
private ParserContext&MockObject $parserContext;
private DocumentParserContext&MockObject $documentParserContext;

public function setUp(): void
{
$this->logger = new Logger('test');
$this->parserContext = $this->createMock(ParserContext::class);
$this->documentParserContext = $this->createMock(DocumentParserContext::class);
$this->referenceTextRole = new ReferenceTextRole($this->logger);
}

Expand All @@ -30,7 +30,7 @@ public function testReferenceIsParsedIntoRefReferenceNode(
string $url,
string|null $text = null,
): void {
$result = $this->referenceTextRole->processNode($this->parserContext, 'doc', $span, $span);
$result = $this->referenceTextRole->processNode($this->documentParserContext, 'doc', $span, $span);

self::assertInstanceOf(ReferenceNode::class, $result);
self::assertEquals($url, $result->getTargetReference(), 'ReferenceNames are different');
Expand Down

0 comments on commit bde5c01

Please sign in to comment.