1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Cleanup logical operators

This commit is contained in:
Aidan Woods 2019-01-26 14:51:05 +00:00
parent 19e21f2d1b
commit d733c262c2
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
19 changed files with 35 additions and 34 deletions

View File

@ -13,6 +13,7 @@ $rules = [
'braces' => [
'allow_single_line_closure' => true,
],
'logical_operators' => true,
'native_constant_invocation' => [
'fix_built_in' => true,
],

View File

@ -68,7 +68,7 @@ final class BlockQuote implements ContinuableBlock
return null;
}
if ($Context->line()->text()[0] === '>' and \preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)) {
if ($Context->line()->text()[0] === '>' && \preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)) {
$indentOffset = $Context->line()->indentOffset() + $Context->line()->indent() + \strlen($matches[1]);
$recoveredSpaces = 0;

View File

@ -90,7 +90,7 @@ final class FencedCode implements ContinuableBlock
}
if (($len = \strspn($Context->line()->text(), $this->marker)) >= $this->openerLength
and \chop(\substr($Context->line()->text(), $len), ' ') === ''
&& \chop(\substr($Context->line()->text(), $len), ' ') === ''
) {
$newCode = \substr($newCode, 1);

View File

@ -60,7 +60,7 @@ final class Header implements Block
if (
$State->get(StrictMode::class)->isEnabled() && isset($text[0])
and $text[0] !== ' ' and $text[0] !== "\t"
&& $text[0] !== ' ' && $text[0] !== "\t"
) {
return null;
}

View File

@ -36,7 +36,7 @@ final class IndentedCode implements ContinuableBlock
Block $Block = null,
State $State = null
) {
if (isset($Block) and $Block instanceof Paragraph and ! $Context->previousEmptyLines() > 0) {
if (isset($Block) && $Block instanceof Paragraph && ! $Context->previousEmptyLines() > 0) {
return null;
}

View File

@ -36,7 +36,7 @@ final class Reference implements StateUpdatingBlock
$State = $State ?: new State;
if (\strpos($Context->line()->text(), ']') !== false
and \preg_match(
&& \preg_match(
'/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/',
$Context->line()->text(),
$matches

View File

@ -31,7 +31,7 @@ final class Rule implements Block
if (
\substr_count($Context->line()->text(), $marker) >= 3
and \chop($Context->line()->text(), " \t$marker") === ''
&& \chop($Context->line()->text(), " \t$marker") === ''
) {
return new self;
}

View File

@ -46,7 +46,7 @@ final class SetextHeader implements Block
return null;
}
if ($Context->line()->indent() < 4 and \chop(\chop($Context->line()->text(), " \t"), $Context->line()->text()[0]) === '') {
if ($Context->line()->indent() < 4 && \chop(\chop($Context->line()->text(), " \t"), $Context->line()->text()[0]) === '') {
$level = $Context->line()->text()[0] === '=' ? 1 : 2;
return new self($Block->text(), $level);

View File

@ -134,9 +134,9 @@ final class TList implements ContinuableBlock
if (
$listStart !== '1'
and isset($Block)
and $Block instanceof Paragraph
and ! $Context->previousEmptyLines() > 0
&& isset($Block)
&& $Block instanceof Paragraph
&& ! $Context->previousEmptyLines() > 0
) {
return null;
}
@ -162,7 +162,7 @@ final class TList implements ContinuableBlock
*/
public function advance(Context $Context)
{
if ($Context->previousEmptyLines() > 0 and \end($this->Lis)->isEmpty()) {
if ($Context->previousEmptyLines() > 0 && \end($this->Lis)->isEmpty()) {
return null;
}
@ -298,9 +298,9 @@ final class TList implements ContinuableBlock
$Renderables = $State->applyTo((new Parsedown($State))->lines($Lines));
if (! $Lines->containsBlankLines()
and isset($Renderables[0])
and $Renderables[0] instanceof Element
and $Renderables[0]->name() === 'p'
&& isset($Renderables[0])
&& $Renderables[0] instanceof Element
&& $Renderables[0]->name() === 'p'
) {
$Contents = $Renderables[0]->contents();
unset($Renderables[0]);

View File

@ -52,15 +52,15 @@ final class Table implements ContinuableBlock
Block $Block = null,
State $State = null
) {
if (! isset($Block) or ! $Block instanceof Paragraph or $Context->previousEmptyLines() > 0) {
if (! isset($Block) || ! $Block instanceof Paragraph || $Context->previousEmptyLines() > 0) {
return null;
}
if (
\strpos($Block->text(), '|') === false
and \strpos($Context->line()->text(), '|') === false
and \strpos($Context->line()->text(), ':') === false
or \strpos($Block->text(), "\n") !== false
&& \strpos($Context->line()->text(), '|') === false
&& \strpos($Context->line()->text(), ':') === false
|| \strpos($Block->text(), "\n") !== false
) {
return null;
}
@ -101,7 +101,7 @@ final class Table implements ContinuableBlock
return null;
}
if (\count($this->alignments) !== 1 and $Context->line()->text()[0] !== '|' and !\strpos($Context->line()->text(), '|')) {
if (\count($this->alignments) !== 1 && $Context->line()->text()[0] !== '|' && !\strpos($Context->line()->text(), '|')) {
return null;
}
@ -109,8 +109,8 @@ final class Table implements ContinuableBlock
if (
! \preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]++`|`)++/', $row, $matches)
or ! isset($matches[0])
or ! \is_array($matches[0])
|| ! isset($matches[0])
|| ! \is_array($matches[0])
) {
return null;
}

View File

@ -44,7 +44,7 @@ final class Email implements Inline
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
if (\strpos($Excerpt->text(), '>') !== false
and \preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt->text(), $matches)
&& \preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt->text(), $matches)
) {
$url = $matches[1];

View File

@ -58,7 +58,7 @@ final class Emphasis implements Inline
$marker = $Excerpt->text()[0] === '*' ? '*' : '_';
if ($Excerpt->text()[1] === $marker and \preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)) {
if ($Excerpt->text()[1] === $marker && \preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)) {
$emphasis = 'strong';
} elseif (\preg_match(self::$EM_REGEX[$marker], $Excerpt->text(), $matches)) {
$emphasis = 'em';

View File

@ -34,7 +34,7 @@ final class EscapeSequence implements Inline
*/
public static function build(Excerpt $Excerpt, State $State)
{
if (isset($Excerpt->text()[1]) and \strpbrk($c = $Excerpt->text()[1], self::SPECIALS) !== false) {
if (isset($Excerpt->text()[1]) && \strpbrk($c = $Excerpt->text()[1], self::SPECIALS) !== false) {
return new self($c);
}

View File

@ -42,15 +42,15 @@ final class Markup implements Inline
$secondChar = \substr($Excerpt->text(), 1, 1);
if ($secondChar === '/' and \preg_match('/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt->text(), $matches)) {
if ($secondChar === '/' && \preg_match('/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt->text(), $matches)) {
return new self($matches[0]);
}
if ($secondChar === '!' and \preg_match('/^<!---?[^>-](?:-?+[^-])*-->/s', $Excerpt->text(), $matches)) {
if ($secondChar === '!' && \preg_match('/^<!---?[^>-](?:-?+[^-])*-->/s', $Excerpt->text(), $matches)) {
return new self($matches[0]);
}
if ($secondChar !== ' ' and \preg_match('/^<\w[\w-]*+(?:[ ]*+'.self::HTML_ATT_REGEX.')*+[ ]*+\/?>/s', $Excerpt->text(), $matches)) {
if ($secondChar !== ' ' && \preg_match('/^<\w[\w-]*+(?:[ ]*+'.self::HTML_ATT_REGEX.')*+[ ]*+\/?>/s', $Excerpt->text(), $matches)) {
return new self($matches[0]);
}
}

View File

@ -32,8 +32,8 @@ final class SpecialCharacter implements Inline
*/
public static function build(Excerpt $Excerpt, State $State)
{
if (\substr($Excerpt->text(), 1, 1) !== ' ' and \strpos($Excerpt->text(), ';') !== false
and \preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt->text(), $matches)
if (\substr($Excerpt->text(), 1, 1) !== ' ' && \strpos($Excerpt->text(), ';') !== false
&& \preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt->text(), $matches)
) {
return new self($matches[1]);
}

View File

@ -41,7 +41,7 @@ final class Strikethrough implements Inline
return null;
}
if ($text[1] === '~' and \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) {
if ($text[1] === '~' && \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) {
return new self($matches[1], \strlen($matches[0]));
}

View File

@ -39,12 +39,12 @@ final class Url implements Inline
{
$text = $Excerpt->text();
if (\strlen($text) < 2 or \substr($text, 2, 1) !== '/') {
if (\strlen($text) < 2 || \substr($text, 2, 1) !== '/') {
return null;
}
if (\strpos($Excerpt->context(), 'http') !== false
and \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt->context(), $matches, \PREG_OFFSET_CAPTURE)
&& \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt->context(), $matches, \PREG_OFFSET_CAPTURE)
) {
return new self($matches[0][0], \intval($matches[0][1]));
}

View File

@ -33,7 +33,7 @@ final class UrlTag implements Inline
*/
public static function build(Excerpt $Excerpt, State $State)
{
if (\strpos($Excerpt->text(), '>') !== false and \preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt->text(), $matches)) {
if (\strpos($Excerpt->text(), '>') !== false && \preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt->text(), $matches)) {
return new self($matches[1], \strlen($matches[0]));
}

View File

@ -125,7 +125,7 @@ final class Parsedown
}
}
if (isset($CurrentBlock) and $CurrentBlock instanceof Paragraph) {
if (isset($CurrentBlock) && $CurrentBlock instanceof Paragraph) {
$Block = $CurrentBlock->advance($Context);
}