Skip to content

Commit bde5c01

Browse files
committed
[FEATURE] Make DocumentParserContext Available in Text Roles
TextRoles might also need the DocumentParserContext
1 parent 176b442 commit bde5c01

File tree

10 files changed

+24
-25
lines changed

10 files changed

+24
-25
lines changed

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/TextRoleRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function apply(DocumentParserContext $documentParserContext, InlineLexer
5858
$fullRole = ($domain ? $domain . ':' : '') . $role;
5959
$lexer->moveNext();
6060

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

6464
$inText = true;

packages/guides-restructured-text/src/RestructuredText/TextRoles/AbbreviationTextRole.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use phpDocumentor\Guides\Nodes\Inline\AbbreviationInlineNode;
88
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
9-
use phpDocumentor\Guides\ParserContext;
9+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1010
use Psr\Log\LoggerInterface;
1111

1212
use function preg_match;
@@ -34,7 +34,7 @@ public function getAliases(): array
3434

3535
/** @return AbbreviationInlineNode */
3636
public function processNode(
37-
ParserContext $parserContext,
37+
DocumentParserContext $documentParserContext,
3838
string $role,
3939
string $content,
4040
string $rawContent,
@@ -45,7 +45,7 @@ public function processNode(
4545

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

5151
return new AbbreviationInlineNode($content, '');

packages/guides-restructured-text/src/RestructuredText/TextRoles/AbstractReferenceTextRole.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
66

77
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
8-
use phpDocumentor\Guides\ParserContext;
8+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
99
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1010
use Psr\Log\LoggerInterface;
1111

@@ -25,7 +25,7 @@ public function __construct(
2525
}
2626

2727
public function processNode(
28-
ParserContext $parserContext,
28+
DocumentParserContext $documentParserContext,
2929
string $role,
3030
string $content,
3131
string $rawContent,
@@ -58,7 +58,7 @@ public function processNode(
5858
'Reference contains unexpected content after closing `>`: "%s"',
5959
$content,
6060
),
61-
$parserContext->getLoggerInformation(),
61+
$documentParserContext->getContext()->getLoggerInformation(),
6262
);
6363
}
6464

packages/guides-restructured-text/src/RestructuredText/TextRoles/GenericTextRole.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
66

77
use phpDocumentor\Guides\Nodes\Inline\GenericTextRoleInlineNode;
8-
use phpDocumentor\Guides\ParserContext;
8+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
99

1010
class GenericTextRole implements TextRole
1111
{
@@ -23,7 +23,7 @@ public function getAliases(): array
2323
}
2424

2525
public function processNode(
26-
ParserContext $parserContext,
26+
DocumentParserContext $documentParserContext,
2727
string $role,
2828
string $content,
2929
string $rawContent,

packages/guides-restructured-text/src/RestructuredText/TextRoles/LiteralTextRole.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
66

77
use phpDocumentor\Guides\Nodes\Inline\GenericTextRoleInlineNode;
8-
use phpDocumentor\Guides\ParserContext;
8+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
99

1010
class LiteralTextRole implements TextRole
1111
{
@@ -23,7 +23,7 @@ public function getAliases(): array
2323
}
2424

2525
public function processNode(
26-
ParserContext $parserContext,
26+
DocumentParserContext $documentParserContext,
2727
string $role,
2828
string $content,
2929
string $rawContent,

packages/guides-restructured-text/src/RestructuredText/TextRoles/MathTextRole.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
66

77
use phpDocumentor\Guides\Nodes\Inline\GenericTextRoleInlineNode;
8-
use phpDocumentor\Guides\ParserContext;
8+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
99

1010
class MathTextRole implements TextRole
1111
{
@@ -23,7 +23,7 @@ public function getAliases(): array
2323
}
2424

2525
public function processNode(
26-
ParserContext $parserContext,
26+
DocumentParserContext $documentParserContext,
2727
string $role,
2828
string $content,
2929
string $rawContent,

packages/guides-restructured-text/src/RestructuredText/TextRoles/TextRole.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
66

77
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
8-
use phpDocumentor\Guides\ParserContext;
8+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
99

1010
interface TextRole
1111
{
@@ -19,7 +19,7 @@ public function getAliases(): array;
1919
* @param string $rawContent the raw content, including backslash escapes
2020
*/
2121
public function processNode(
22-
ParserContext $parserContext,
22+
DocumentParserContext $documentParserContext,
2323
string $role,
2424
string $content,
2525
string $rawContent,

packages/guides-restructured-text/tests/unit/Parser/Productions/InlineRules/TextRoleRuleTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Generator;
88
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
9-
use phpDocumentor\Guides\ParserContext;
109
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1110
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
1211
use phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules\TextRoleRule;
@@ -65,7 +64,7 @@ public function getAliases(): array
6564
return [];
6665
}
6766

68-
public function processNode(ParserContext $parserContext, string $role, string $content, string $rawContent): InlineNode
67+
public function processNode(DocumentParserContext $documentParserContext, string $role, string $content, string $rawContent): InlineNode
6968
{
7069
return new class ($role, $content, $rawContent) extends InlineNode {
7170
public function __construct(

packages/guides-restructured-text/tests/unit/TextRoles/DocReferenceTextRoleTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Monolog\Logger;
88
use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
9-
use phpDocumentor\Guides\ParserContext;
9+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1010
use PHPUnit\Framework\Attributes\DataProvider;
1111
use PHPUnit\Framework\MockObject\MockObject;
1212
use PHPUnit\Framework\TestCase;
@@ -15,12 +15,12 @@ class DocReferenceTextRoleTest extends TestCase
1515
{
1616
private Logger $logger;
1717
private DocReferenceTextRole $docReferenceTextRole;
18-
private ParserContext&MockObject $parserContext;
18+
private DocumentParserContext&MockObject $documentParserContext;
1919

2020
public function setUp(): void
2121
{
2222
$this->logger = new Logger('test');
23-
$this->parserContext = $this->createMock(ParserContext::class);
23+
$this->documentParserContext = $this->createMock(DocumentParserContext::class);
2424
$this->docReferenceTextRole = new DocReferenceTextRole($this->logger);
2525
}
2626

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

3535
self::assertInstanceOf(DocReferenceNode::class, $result);
3636
self::assertEquals($url, $result->getTargetReference(), 'DocumentLinks are different');

packages/guides-restructured-text/tests/unit/TextRoles/ReferenceTextRoleTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Monolog\Logger;
88
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
9-
use phpDocumentor\Guides\ParserContext;
9+
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1010
use PHPUnit\Framework\Attributes\DataProvider;
1111
use PHPUnit\Framework\MockObject\MockObject;
1212
use PHPUnit\Framework\TestCase;
@@ -15,12 +15,12 @@ class ReferenceTextRoleTest extends TestCase
1515
{
1616
private Logger $logger;
1717
private ReferenceTextRole $referenceTextRole;
18-
private ParserContext&MockObject $parserContext;
18+
private DocumentParserContext&MockObject $documentParserContext;
1919

2020
public function setUp(): void
2121
{
2222
$this->logger = new Logger('test');
23-
$this->parserContext = $this->createMock(ParserContext::class);
23+
$this->documentParserContext = $this->createMock(DocumentParserContext::class);
2424
$this->referenceTextRole = new ReferenceTextRole($this->logger);
2525
}
2626

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

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

0 commit comments

Comments
 (0)