Skip to content

Commit 9fb9559

Browse files
author
Martin Brecht-Precht
committed
WIP: Language level migration.
1 parent 66d137f commit 9fb9559

File tree

16 files changed

+188
-184
lines changed

16 files changed

+188
-184
lines changed

composer.json

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
{
2-
"name": "markdom/handler",
3-
"type": "library",
4-
"description": "Handler and dispatcher implementations written in PHP",
5-
"keywords": [
6-
"Markdom",
7-
"Handler",
8-
"Dispatcher"
9-
],
10-
"homepage": "http://markenwerk.net/",
11-
"license": "MIT",
12-
"authors": [
13-
{
14-
"name": "Martin Brecht-Precht",
15-
"email": "mb@markenwerk.net",
16-
"homepage": "http://markenwerk.net"
17-
}
18-
],
19-
"autoload": {
20-
"psr-4": {
21-
"Markdom\\Handler\\": "src/Handler",
22-
"Markdom\\Dispatcher\\": "src/Dispatcher"
23-
}
24-
},
25-
"require": {
26-
"php": ">=5.3",
27-
"markdom/handler-interface": "^1.0.10",
28-
"markenwerk/stack-util": "~1.0",
29-
"markenwerk/string-builder": "^1.0.4",
30-
"markenwerk/json-pretty-printer": "~1.0",
31-
"mustangostang/spyc": ">=0.6.1",
32-
"league/commonmark": "^0.13"
33-
}
2+
"name": "markdom/handler",
3+
"type": "library",
4+
"description": "Handler and dispatcher implementations written in PHP",
5+
"keywords": [
6+
"Markdom",
7+
"Handler",
8+
"Dispatcher"
9+
],
10+
"homepage": "http://markenwerk.net/",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Martin Brecht-Precht",
15+
"email": "mb@markenwerk.net",
16+
"homepage": "http://markenwerk.net"
17+
}
18+
],
19+
"autoload": {
20+
"psr-4": {
21+
"Markdom\\Handler\\": "src/Handler",
22+
"Markdom\\Dispatcher\\": "src/Dispatcher"
23+
}
24+
},
25+
"require": {
26+
"php": "^7.1",
27+
"ext-dom": "*",
28+
"ext-json": "*",
29+
"ext-mbstring": "*",
30+
"markdom/handler-interface": "^1.1.0",
31+
"markenwerk/stack-util": "~1.0",
32+
"markenwerk/string-builder": "^1.0.4",
33+
"markenwerk/json-pretty-printer": "~1.0",
34+
"mustangostang/spyc": ">=0.6.1",
35+
"league/commonmark": "^0.13"
36+
}
3437
}

src/Dispatcher/CommonmarkDispatcher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class CommonmarkDispatcher implements DispatcherInterface
3232
*
3333
* @param string $commonmarkString
3434
*/
35-
public function __construct($commonmarkString)
35+
public function __construct(string $commonmarkString)
3636
{
3737
$this->commonmarkString = $commonmarkString;
3838
}
3939

4040
/**
4141
* @return HtmlProcessorInterface
4242
*/
43-
public function getHtmlProcessor()
43+
public function getHtmlProcessor():HtmlProcessorInterface
4444
{
4545
return $this->htmlProcessor;
4646
}
@@ -49,7 +49,7 @@ public function getHtmlProcessor()
4949
* @param HtmlProcessorInterface $htmlProcessor
5050
* @return $this
5151
*/
52-
public function setHtmlProcessor($htmlProcessor)
52+
public function setHtmlProcessor(HtmlProcessorInterface $htmlProcessor)
5353
{
5454
$this->htmlProcessor = $htmlProcessor;
5555
return $this;
@@ -58,7 +58,7 @@ public function setHtmlProcessor($htmlProcessor)
5858
/**
5959
* @return bool
6060
*/
61-
public function isReusable()
61+
public function isReusable():bool
6262
{
6363
return true;
6464
}

src/Dispatcher/CommonmarkUtil/DocumentProcessor.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@
1818
final class DocumentProcessor implements DocumentProcessorInterface
1919
{
2020

21-
const BLOCK_NODE_BLOCK_QUOTE = 'League\CommonMark\Block\Element\BlockQuote';
22-
const BLOCK_NODE_DOCUMENT = 'League\CommonMark\Block\Element\Document';
23-
const BLOCK_NODE_EMPHASIS = 'League\CommonMark\Inline\Element\Emphasis';
24-
const BLOCK_NODE_FENCED_CODE = 'League\CommonMark\Block\Element\FencedCode';
25-
const BLOCK_NODE_HEADING = 'League\CommonMark\Block\Element\Heading';
26-
const BLOCK_NODE_HTML_BLOCK = 'League\CommonMark\Block\Element\HtmlBlock';
27-
const BLOCK_NODE_IMAGE = 'League\CommonMark\Inline\Element\Image';
28-
const BLOCK_NODE_INDENTED_CODE = 'League\CommonMark\Block\Element\IndentedCode';
29-
const BLOCK_NODE_INLINE_CONTAINER = 'League\CommonMark\Block\Element\InlineContainer';
30-
const BLOCK_NODE_LINK = 'League\CommonMark\Inline\Element\Link';
31-
const BLOCK_NODE_LIST_BLOCK = 'League\CommonMark\Block\Element\ListBlock';
32-
const BLOCK_NODE_LIST_DATA = 'League\CommonMark\Block\Element\ListData';
33-
const BLOCK_NODE_LIST_ITEM = 'League\CommonMark\Block\Element\ListItem';
34-
const BLOCK_NODE_PARAGRAPH = 'League\CommonMark\Block\Element\Paragraph';
35-
const BLOCK_NODE_STRONG = 'League\CommonMark\Inline\Element\Strong';
36-
const BLOCK_NODE_THEMATIC_BREAK = 'League\CommonMark\Block\Element\ThematicBreak';
21+
public const BLOCK_NODE_BLOCK_QUOTE = 'League\CommonMark\Block\Element\BlockQuote';
22+
public const BLOCK_NODE_DOCUMENT = 'League\CommonMark\Block\Element\Document';
23+
public const BLOCK_NODE_EMPHASIS = 'League\CommonMark\Inline\Element\Emphasis';
24+
public const BLOCK_NODE_FENCED_CODE = 'League\CommonMark\Block\Element\FencedCode';
25+
public const BLOCK_NODE_HEADING = 'League\CommonMark\Block\Element\Heading';
26+
public const BLOCK_NODE_HTML_BLOCK = 'League\CommonMark\Block\Element\HtmlBlock';
27+
public const BLOCK_NODE_IMAGE = 'League\CommonMark\Inline\Element\Image';
28+
public const BLOCK_NODE_INDENTED_CODE = 'League\CommonMark\Block\Element\IndentedCode';
29+
public const BLOCK_NODE_INLINE_CONTAINER = 'League\CommonMark\Block\Element\InlineContainer';
30+
public const BLOCK_NODE_LINK = 'League\CommonMark\Inline\Element\Link';
31+
public const BLOCK_NODE_LIST_BLOCK = 'League\CommonMark\Block\Element\ListBlock';
32+
public const BLOCK_NODE_LIST_DATA = 'League\CommonMark\Block\Element\ListData';
33+
public const BLOCK_NODE_LIST_ITEM = 'League\CommonMark\Block\Element\ListItem';
34+
public const BLOCK_NODE_PARAGRAPH = 'League\CommonMark\Block\Element\Paragraph';
35+
public const BLOCK_NODE_STRONG = 'League\CommonMark\Inline\Element\Strong';
36+
public const BLOCK_NODE_THEMATIC_BREAK = 'League\CommonMark\Block\Element\ThematicBreak';
3737

38-
const INLINE_NODE_CODE = 'League\CommonMark\Inline\Element\Code';
39-
const INLINE_NODE_HTML_INLINE = 'League\CommonMark\Inline\Element\HtmlInline';
40-
const INLINE_NODE_NEWLINE = 'League\CommonMark\Inline\Element\Newline';
41-
const INLINE_NODE_TEXT = 'League\CommonMark\Inline\Element\Text';
38+
public const INLINE_NODE_CODE = 'League\CommonMark\Inline\Element\Code';
39+
public const INLINE_NODE_HTML_INLINE = 'League\CommonMark\Inline\Element\HtmlInline';
40+
public const INLINE_NODE_NEWLINE = 'League\CommonMark\Inline\Element\Newline';
41+
public const INLINE_NODE_TEXT = 'League\CommonMark\Inline\Element\Text';
4242

4343
/**
4444
* @var HandlerInterface
@@ -78,7 +78,7 @@ public function __construct(
7878
* @return void
7979
* @throws DispatcherException
8080
*/
81-
public function processDocument(Document $document)
81+
public function processDocument(Document $document): void
8282
{
8383
$markdomHandlerEventDispatcher = new MarkdomEventBridge(
8484
$this->markdomHandler,

src/Dispatcher/CommonmarkUtil/MarkdomEventBridge.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ public function dispatchMarkdomEvent(NodeWalkerEvent $commonMarkEvent)
7676
} else {
7777
$this->transmitInlineBeginEvent($node);
7878
}
79-
} else {
80-
if ($node->isContainer()) {
81-
$this->transmitContainerEndEvent($node);
82-
}
79+
} else if ($node->isContainer()) {
80+
$this->transmitContainerEndEvent($node);
8381
}
8482
return $this;
8583
}
@@ -106,7 +104,7 @@ private function dispatchBlocksEndEvents()
106104
* @param string $type
107105
* @return $this
108106
*/
109-
private function dispatchBlockBeginEvents($type)
107+
private function dispatchBlockBeginEvents(string $type)
110108
{
111109
$this->markdomHandler->onBlockBegin($type);
112110
return $this;
@@ -117,7 +115,7 @@ private function dispatchBlockBeginEvents($type)
117115
* @param string $type
118116
* @return $this
119117
*/
120-
private function dispatchBlockEndEvents($node, $type)
118+
private function dispatchBlockEndEvents(Node $node, string $type)
121119
{
122120
$this->markdomHandler->onBlockEnd($type);
123121
if (!is_null($node->next())) {
@@ -130,7 +128,7 @@ private function dispatchBlockEndEvents($node, $type)
130128
* @param string $type
131129
* @return $this
132130
*/
133-
private function dispatchContentBeginEvents($type)
131+
private function dispatchContentBeginEvents(string $type)
134132
{
135133
$this->markdomHandler->onContentBegin($type);
136134
return $this;
@@ -141,7 +139,7 @@ private function dispatchContentBeginEvents($type)
141139
* @param string $type
142140
* @return $this
143141
*/
144-
private function dispatchContentEndEvents($node, $type)
142+
private function dispatchContentEndEvents(Node $node, string $type)
145143
{
146144
$this->markdomHandler->onContentEnd($type);
147145
if (!is_null($node->next())) {
@@ -170,9 +168,10 @@ private function dispatchContentsEndEvents()
170168

171169
/**
172170
* @param Node $node
171+
* @return void
173172
* @throws DispatcherException
174173
*/
175-
private function transmitContainerBeginEvent(Node $node)
174+
private function transmitContainerBeginEvent(Node $node): void
176175
{
177176
switch (get_class($node)) {
178177
case DocumentProcessor::BLOCK_NODE_BLOCK_QUOTE:
@@ -286,9 +285,10 @@ private function transmitContainerBeginEvent(Node $node)
286285

287286
/**
288287
* @param Node $node
288+
* @return void
289289
* @throws DispatcherException
290290
*/
291-
private function transmitContainerEndEvent(Node $node)
291+
private function transmitContainerEndEvent(Node $node): void
292292
{
293293
switch (get_class($node)) {
294294
case DocumentProcessor::BLOCK_NODE_BLOCK_QUOTE:
@@ -377,9 +377,10 @@ private function transmitContainerEndEvent(Node $node)
377377

378378
/**
379379
* @param Node $node
380+
* @return void
380381
* @throws DispatcherException
381382
*/
382-
private function transmitInlineBeginEvent(Node $node)
383+
private function transmitInlineBeginEvent(Node $node): void
383384
{
384385
switch (get_class($node)) {
385386
case DocumentProcessor::INLINE_NODE_CODE:
@@ -412,7 +413,7 @@ private function transmitInlineBeginEvent(Node $node)
412413
/**
413414
* @throws DispatcherException
414415
*/
415-
private function transmitInlineEndEvent()
416+
private function transmitInlineEndEvent(): void
416417
{
417418
if (is_null($this->recentInlineNode)) {
418419
return;

src/Dispatcher/CommonmarkUtil/PlaintextWalker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function processNode(Node $node)
5959
/**
6060
* @return string
6161
*/
62-
public function getPlaintext()
62+
public function getPlaintext(): string
6363
{
6464
return $this->plaintextBuilder->build();
6565
}
@@ -68,7 +68,7 @@ public function getPlaintext()
6868
* @param string $plaintext
6969
* @return $this
7070
*/
71-
private function appendPlaintext($plaintext)
71+
private function appendPlaintext(string $plaintext)
7272
{
7373
$this->plaintextBuilder->append($plaintext);
7474
return $this;

0 commit comments

Comments
 (0)