Don't globally disable PHPCS's prohibition of assert()
authorKunal Mehta <legoktm@member.fsf.org>
Mon, 7 May 2018 08:09:19 +0000 (01:09 -0700)
committerUmherirrender <umherirrender_de.wp@web.de>
Mon, 7 May 2018 17:15:16 +0000 (17:15 +0000)
Whitelist the remaining usages of assert(), and reinstate the PHPCS sniff
that forbids usage of it. Add FIXME comments as well, so any casual readers
of the code will not think that the disabling and usage is intentional.

Change-Id: I7cabe715c0e6aa6a9ef3ffe5657f3de7fd8e662b

.phpcs.xml
includes/diff/DiffEngine.php
includes/diff/WordAccumulator.php
includes/parser/Preprocessor_DOM.php
includes/parser/Preprocessor_Hash.php

index 31e6eeb..d43a281 100644 (file)
@@ -17,7 +17,6 @@
                <exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.SingleSpaceBeforeSingleLineComment" />
                <exclude name="MediaWiki.Usage.DbrQueryUsage.DbrQueryFound" />
                <exclude name="MediaWiki.Usage.ExtendClassUsage.FunctionVarUsage" />
-               <exclude name="MediaWiki.Usage.ForbiddenFunctions.assert" />
                <exclude name="MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals" />
                <exclude name="MediaWiki.Files.ClassMatchesFilename.WrongCase" />
                <exclude name="MediaWiki.Files.ClassMatchesFilename.NotMatch" />
index 53378e5..273d1d6 100644 (file)
@@ -24,6 +24,9 @@
  */
 use MediaWiki\Diff\ComplexityException;
 
+// FIXME: Don't use assert() in this file
+// phpcs:disable MediaWiki.Usage.ForbiddenFunctions.assert
+
 /**
  * This diff implementation is mainly lifted from the LCS algorithm of the Eclipse project which
  * in turn is based on Myers' "An O(ND) difference algorithm and its variations"
index ad80275..88631ed 100644 (file)
@@ -89,6 +89,8 @@ class WordAccumulator {
                                $this->flushLine( $tag );
                                $word = substr( $word, 1 );
                        }
+                       // FIXME: Don't use assert()
+                       // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.assert
                        assert( !strstr( $word, "\n" ) );
                        $this->group .= $word;
                }
index 64edbb2..104cd13 100644 (file)
@@ -566,6 +566,8 @@ class Preprocessor_DOM extends Preprocessor {
                        } elseif ( $found == 'line-end' ) {
                                $piece = $stack->top;
                                // A heading must be open, otherwise \n wouldn't have been in the search list
+                               // FIXME: Don't use assert()
+                               // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.assert
                                assert( $piece->open === "\n" );
                                $part = $piece->getCurrentPart();
                                // Search back through the input to see if it has a proper close.
index c7f630d..8e74380 100644 (file)
@@ -504,6 +504,8 @@ class Preprocessor_Hash extends Preprocessor {
                        } elseif ( $found == 'line-end' ) {
                                $piece = $stack->top;
                                // A heading must be open, otherwise \n wouldn't have been in the search list
+                               // FIXME: Don't use assert()
+                               // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.assert
                                assert( $piece->open === "\n" );
                                $part = $piece->getCurrentPart();
                                // Search back through the input to see if it has a proper close.