From d733c262c235901b3181325e954db96588c1443a Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sat, 26 Jan 2019 14:51:05 +0000 Subject: [PATCH] Cleanup logical operators --- .php_cs.dist | 1 + src/Components/Blocks/BlockQuote.php | 2 +- src/Components/Blocks/FencedCode.php | 2 +- src/Components/Blocks/Header.php | 2 +- src/Components/Blocks/IndentedCode.php | 2 +- src/Components/Blocks/Reference.php | 2 +- src/Components/Blocks/Rule.php | 2 +- src/Components/Blocks/SetextHeader.php | 2 +- src/Components/Blocks/TList.php | 14 +++++++------- src/Components/Blocks/Table.php | 14 +++++++------- src/Components/Inlines/Email.php | 2 +- src/Components/Inlines/Emphasis.php | 2 +- src/Components/Inlines/EscapeSequence.php | 2 +- src/Components/Inlines/Markup.php | 6 +++--- src/Components/Inlines/SpecialCharacter.php | 4 ++-- src/Components/Inlines/Strikethrough.php | 2 +- src/Components/Inlines/Url.php | 4 ++-- src/Components/Inlines/UrlTag.php | 2 +- src/Parsedown.php | 2 +- 19 files changed, 35 insertions(+), 34 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 9184af0..e3a720c 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -13,6 +13,7 @@ $rules = [ 'braces' => [ 'allow_single_line_closure' => true, ], + 'logical_operators' => true, 'native_constant_invocation' => [ 'fix_built_in' => true, ], diff --git a/src/Components/Blocks/BlockQuote.php b/src/Components/Blocks/BlockQuote.php index c059e00..d97c85d 100644 --- a/src/Components/Blocks/BlockQuote.php +++ b/src/Components/Blocks/BlockQuote.php @@ -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; diff --git a/src/Components/Blocks/FencedCode.php b/src/Components/Blocks/FencedCode.php index 118c463..74b7608 100644 --- a/src/Components/Blocks/FencedCode.php +++ b/src/Components/Blocks/FencedCode.php @@ -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); diff --git a/src/Components/Blocks/Header.php b/src/Components/Blocks/Header.php index 5cfefe3..a53bae1 100644 --- a/src/Components/Blocks/Header.php +++ b/src/Components/Blocks/Header.php @@ -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; } diff --git a/src/Components/Blocks/IndentedCode.php b/src/Components/Blocks/IndentedCode.php index db1c445..53d426a 100644 --- a/src/Components/Blocks/IndentedCode.php +++ b/src/Components/Blocks/IndentedCode.php @@ -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; } diff --git a/src/Components/Blocks/Reference.php b/src/Components/Blocks/Reference.php index db35a21..4ba0987 100644 --- a/src/Components/Blocks/Reference.php +++ b/src/Components/Blocks/Reference.php @@ -36,7 +36,7 @@ final class Reference implements StateUpdatingBlock $State = $State ?: new State; if (\strpos($Context->line()->text(), ']') !== false - and \preg_match( + && \preg_match( '/^\[(.+?)\]:[ ]*+?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $Context->line()->text(), $matches diff --git a/src/Components/Blocks/Rule.php b/src/Components/Blocks/Rule.php index eb1f2ed..ceb7b6a 100644 --- a/src/Components/Blocks/Rule.php +++ b/src/Components/Blocks/Rule.php @@ -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; } diff --git a/src/Components/Blocks/SetextHeader.php b/src/Components/Blocks/SetextHeader.php index 65148b3..17282cb 100644 --- a/src/Components/Blocks/SetextHeader.php +++ b/src/Components/Blocks/SetextHeader.php @@ -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); diff --git a/src/Components/Blocks/TList.php b/src/Components/Blocks/TList.php index 245b34e..de4d51c 100644 --- a/src/Components/Blocks/TList.php +++ b/src/Components/Blocks/TList.php @@ -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]); diff --git a/src/Components/Blocks/Table.php b/src/Components/Blocks/Table.php index 5536b6e..194abc7 100644 --- a/src/Components/Blocks/Table.php +++ b/src/Components/Blocks/Table.php @@ -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; } diff --git a/src/Components/Inlines/Email.php b/src/Components/Inlines/Email.php index cb71e56..d547111 100644 --- a/src/Components/Inlines/Email.php +++ b/src/Components/Inlines/Email.php @@ -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]; diff --git a/src/Components/Inlines/Emphasis.php b/src/Components/Inlines/Emphasis.php index 906e915..52c63de 100644 --- a/src/Components/Inlines/Emphasis.php +++ b/src/Components/Inlines/Emphasis.php @@ -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'; diff --git a/src/Components/Inlines/EscapeSequence.php b/src/Components/Inlines/EscapeSequence.php index 050494c..5008906 100644 --- a/src/Components/Inlines/EscapeSequence.php +++ b/src/Components/Inlines/EscapeSequence.php @@ -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); } diff --git a/src/Components/Inlines/Markup.php b/src/Components/Inlines/Markup.php index b0fb1e6..658cbe1 100644 --- a/src/Components/Inlines/Markup.php +++ b/src/Components/Inlines/Markup.php @@ -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]); } } diff --git a/src/Components/Inlines/SpecialCharacter.php b/src/Components/Inlines/SpecialCharacter.php index e7e7081..d9a920b 100644 --- a/src/Components/Inlines/SpecialCharacter.php +++ b/src/Components/Inlines/SpecialCharacter.php @@ -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]); } diff --git a/src/Components/Inlines/Strikethrough.php b/src/Components/Inlines/Strikethrough.php index bd92818..b66d344 100644 --- a/src/Components/Inlines/Strikethrough.php +++ b/src/Components/Inlines/Strikethrough.php @@ -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])); } diff --git a/src/Components/Inlines/Url.php b/src/Components/Inlines/Url.php index 6113604..754fa2c 100644 --- a/src/Components/Inlines/Url.php +++ b/src/Components/Inlines/Url.php @@ -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])); } diff --git a/src/Components/Inlines/UrlTag.php b/src/Components/Inlines/UrlTag.php index c7ee6ac..befc937 100644 --- a/src/Components/Inlines/UrlTag.php +++ b/src/Components/Inlines/UrlTag.php @@ -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])); } diff --git a/src/Parsedown.php b/src/Parsedown.php index 1bbffb6..cd93cd6 100644 --- a/src/Parsedown.php +++ b/src/Parsedown.php @@ -125,7 +125,7 @@ final class Parsedown } } - if (isset($CurrentBlock) and $CurrentBlock instanceof Paragraph) { + if (isset($CurrentBlock) && $CurrentBlock instanceof Paragraph) { $Block = $CurrentBlock->advance($Context); }