Skip to content

Commit b4e2675

Browse files
author
Martin Brecht-Precht
committed
Refactoring and code cleanup.
1 parent 0f002a7 commit b4e2675

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

src/Dispatcher/CommonmarkUtil/DocumentProcessor.php

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

55
use League\CommonMark\Block\Element\Document;
66
use League\CommonMark\DocumentProcessorInterface;
7+
use Markdom\Dispatcher\Exception\DispatcherException;
78
use Markdom\Dispatcher\HtmlProcessor\HtmlProcessorInterface;
89
use Markdom\Dispatcher\HtmlProcessor\HtmlTextProcessor;
910
use Markdom\HandlerInterface\HandlerInterface;
@@ -75,6 +76,7 @@ public function __construct(
7576
/**
7677
* @param Document $document
7778
* @return void
79+
* @throws DispatcherException
7880
*/
7981
public function processDocument(Document $document)
8082
{

src/Dispatcher/CommonmarkUtil/MarkdomEventBridge.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function __construct(
6464
/**
6565
* @param NodeWalkerEvent $commonMarkEvent
6666
* @return $this
67+
* @throws DispatcherException
6768
*/
6869
public function dispatchMarkdomEvent(NodeWalkerEvent $commonMarkEvent)
6970
{
@@ -202,7 +203,7 @@ private function transmitContainerBeginEvent(Node $node)
202203
break;
203204
case DocumentProcessor::BLOCK_NODE_HTML_BLOCK:
204205
/** @var HtmlBlock $node */
205-
if ($node->getType() == $node::TYPE_2_COMMENT) {
206+
if ($node->getType() === $node::TYPE_2_COMMENT) {
206207
$this->dispatchBlockBeginEvents(BlockType::TYPE_COMMENT);
207208
$comment = $node->getStringContent();
208209
if (mb_strpos($comment, '<!--') === 0) {
@@ -244,7 +245,7 @@ private function transmitContainerBeginEvent(Node $node)
244245
break;
245246
case DocumentProcessor::BLOCK_NODE_LIST_BLOCK:
246247
/** @var ListBlock $node */
247-
$ordered = $node->getListData()->type == ListBlock::TYPE_ORDERED;
248+
$ordered = $node->getListData()->type === ListBlock::TYPE_ORDERED;
248249
if ($ordered) {
249250
$startIndex = $node->getListData()->start;
250251
$this->dispatchBlockBeginEvents(BlockType::TYPE_ORDERED_LIST);
@@ -315,7 +316,7 @@ private function transmitContainerEndEvent(Node $node)
315316
break;
316317
case DocumentProcessor::BLOCK_NODE_HTML_BLOCK:
317318
/** @var HtmlBlock $node */
318-
if ($node->getType() == $node::TYPE_2_COMMENT) {
319+
if ($node->getType() === $node::TYPE_2_COMMENT) {
319320
$this->dispatchBlockEndEvents($node, BlockType::TYPE_COMMENT);
320321
}
321322
break;
@@ -336,7 +337,7 @@ private function transmitContainerEndEvent(Node $node)
336337
case DocumentProcessor::BLOCK_NODE_LIST_BLOCK:
337338
/** @var ListBlock $node */
338339
$this->markdomHandler->onListItemsEnd();
339-
$ordered = $node->getListData()->type == ListBlock::TYPE_ORDERED;
340+
$ordered = $node->getListData()->type === ListBlock::TYPE_ORDERED;
340341
if ($ordered) {
341342
$startIndex = $node->getListData()->start;
342343
$this->markdomHandler->onOrderedListBlockEnd($startIndex);
@@ -393,7 +394,7 @@ private function transmitInlineBeginEvent(Node $node)
393394
case DocumentProcessor::INLINE_NODE_NEWLINE:
394395
$this->dispatchContentBeginEvents(ContentType::TYPE_LINE_BREAK);
395396
/** @var Newline $node */
396-
$hard = $node->getType() == Newline::HARDBREAK;
397+
$hard = $node->getType() === Newline::HARDBREAK;
397398
$this->markdomHandler->onLineBreakContent($hard);
398399
break;
399400
case DocumentProcessor::INLINE_NODE_TEXT:

src/Dispatcher/CommonmarkUtil/PlaintextWalker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function processNode(Node $node)
4040
break;
4141
case DocumentProcessor::INLINE_NODE_NEWLINE:
4242
/** @var Newline $currentNode */
43-
$hard = $currentNode->getType() == Newline::HARDBREAK;
43+
$hard = $currentNode->getType() === Newline::HARDBREAK;
4444
if ($hard) {
4545
$this->appendSpace();
4646
}

src/Handler/CommonmarkHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,10 @@ public function onTextContent($text)
619619
(
620620
!$this->lineStarted
621621
&& $this->inParagraphBlock
622-
&& in_array($character, $this->escapeLineStartCharacterList)
622+
&& in_array($character, $this->escapeLineStartCharacterList, true)
623623
&& ($nextCharacter === ' ' || $nextCharacter === "\t")
624624
)
625-
|| in_array($character, $this->escapeCharacterList)
625+
|| in_array($character, $this->escapeCharacterList, true)
626626
) {
627627
$this->appendPendingDelimiters($builder);
628628
$builder->append('\\' . $character);
@@ -744,7 +744,7 @@ private function appendCode($code, $backticksSequence)
744744
{
745745
$backtickString = str_repeat('`', $backticksSequence);
746746
$this->append($backtickString);
747-
if (mb_substr($code, 0, 1) === '`') {
747+
if (mb_strpos($code, '`') === 0) {
748748
$this->append(' ');
749749
}
750750
$this->append($code);

src/Handler/HtmlHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public function onCodeContent($code)
428428
public function onEmphasisContentBegin($level)
429429
{
430430
$tagType = TagBuilderInterface::TYPE_EMPHASIS_LEVEL_1_BEGIN;
431-
if ($level == EmphasisLevel::LEVEL_2) {
431+
if ($level === EmphasisLevel::LEVEL_2) {
432432
$tagType = TagBuilderInterface::TYPE_EMPHASIS_LEVEL_2_BEGIN;
433433
}
434434
$this->htmlBuilder->append($this->getTagBuilder()->buildTag($tagType));
@@ -441,7 +441,7 @@ public function onEmphasisContentBegin($level)
441441
public function onEmphasisContentEnd($level)
442442
{
443443
$tagType = TagBuilderInterface::TYPE_EMPHASIS_LEVEL_1_END;
444-
if ($level == EmphasisLevel::LEVEL_2) {
444+
if ($level === EmphasisLevel::LEVEL_2) {
445445
$tagType = TagBuilderInterface::TYPE_EMPHASIS_LEVEL_2_END;
446446
}
447447
$this->htmlBuilder->append($this->getTagBuilder()->buildTag($tagType));

src/Handler/HtmlTagBuilder/HtmlTagBuilder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ public function buildTag($type, $value = null, array $attributes = array(), $var
2525
{
2626
switch ($type) {
2727
case self::TYPE_CODE_BLOCK:
28+
/** @noinspection HtmlUnknownTag */
2829
return '<pre><code' . $this->getAttributeString($attributes) . '>' . $value . '</code></pre>';
2930
case self::TYPE_CODE_INLINE:
31+
/** @noinspection HtmlUnknownTag */
3032
return '<code' . $this->getAttributeString($attributes) . '>' . $value . '</code>';
3133
case self::TYPE_COMMENT:
3234
return '<!-- ' . $value . ' -->';
@@ -121,6 +123,7 @@ protected function getAttributeString(array $attributes)
121123
}
122124
$attributeParts[] = mb_strtolower($key) . '="' . $value . '"';
123125
}
126+
unset($value);
124127
if (empty($attributeParts)) {
125128
return '';
126129
}

src/Handler/JsonHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function setEscapeUnicode($escapeUnicode)
6464
public function getResult()
6565
{
6666
if ($this->prettyPrint) {
67-
if (phpversion() && phpversion() >= 5.4) {
67+
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
6868
if ($this->escapeUnicode) {
6969
$options = JSON_PRETTY_PRINT;
7070
} else {

0 commit comments

Comments
 (0)