From ce4867f6dda788da5eecbf8a328e917ce672efe7 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Tue, 7 Mar 2017 09:43:36 -0500 Subject: [PATCH] use yoda condition checks --- .../lib/class-faster-image-b52f1a8-faster-image.php | 4 ++-- .../lib/class-faster-image-b52f1a8-image-parser.php | 12 ++++++------ includes/lib/class-fastimage.php | 8 ++++---- .../sanitizers/class-amp-blacklist-sanitizer.php | 4 ++-- includes/sanitizers/class-amp-style-sanitizer.php | 2 +- includes/utils/class-amp-string-utils.php | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/includes/lib/class-faster-image-b52f1a8-faster-image.php b/includes/lib/class-faster-image-b52f1a8-faster-image.php index 9f7b6c338fc..0f5338c28ab 100644 --- a/includes/lib/class-faster-image-b52f1a8-faster-image.php +++ b/includes/lib/class-faster-image-b52f1a8-faster-image.php @@ -53,7 +53,7 @@ public function batch( array $urls ) { $code = curl_multi_add_handle( $multi, $$count ); - if ( $code !== CURLM_OK ) { + if ( CURLM_OK !== $code ) { throw new \Exception( "Curl handle for $uri could not be added" ); } } @@ -61,7 +61,7 @@ public function batch( array $urls ) { // Perform the requests do { while ( ($mrc = curl_multi_exec( $multi, $active )) === CURLM_CALL_MULTI_PERFORM ) {} - if ( $mrc !== CURLM_OK && $mrc !== CURLM_CALL_MULTI_PERFORM ) { + if ( CURLM_OK !== $mrc && CURLM_CALL_MULTI_PERFORM !== $mrc ) { throw new \Exception( "Curl error code: $mrc" ); } diff --git a/includes/lib/class-faster-image-b52f1a8-image-parser.php b/includes/lib/class-faster-image-b52f1a8-image-parser.php index 2693f38adcd..9bb23a10e29 100644 --- a/includes/lib/class-faster-image-b52f1a8-image-parser.php +++ b/includes/lib/class-faster-image-b52f1a8-image-parser.php @@ -66,8 +66,8 @@ public function parseSizeForIco() { $b2 = $this->getByte(); return [ - $b1 === 0 ? 256 : $b1, - $b2 === 0 ? 256 : $b2, + 0 === $b1 ? 256 : $b1, + 0 === $b2 ? 256 : $b2, ]; } @@ -177,16 +177,16 @@ protected function parseSizeForJPEG() { case 'started': $b = $this->getByte(); - if ( $b === false ) { return false; + if ( false === $b ) { return false; } - $state = $b === 0xFF ? 'sof' : 'started'; + $state = 0xFF === $b ? 'sof' : 'started'; break; case 'sof': $b = $this->getByte(); - if ( $b === 0xe1 ) { + if ( 0xe1 === $b ) { $data = $this->stream->read( $this->readInt( $this->stream->read( 2 ) ) - 2 ); $stream = new Stream_17b32f3_Stream; @@ -209,7 +209,7 @@ protected function parseSizeForJPEG() { $state = 'readsize'; break; } - if ( $b === 0xFF ) { + if ( 0xFF === $b ) { $state = 'sof'; break; } diff --git a/includes/lib/class-fastimage.php b/includes/lib/class-fastimage.php index c48149e9880..e4e2046276b 100644 --- a/includes/lib/class-fastimage.php +++ b/includes/lib/class-fastimage.php @@ -105,9 +105,9 @@ private function parseSizeForJPEG() { break; case 'started': $b = $this->getByte(); - if ( $b === false ) { return false; + if ( false === $b ) { return false; } - $state = $b === 0xFF ? 'sof' : 'started'; + $state = 0xFF === $b ? 'sof' : 'started'; break; case 'sof': $b = $this->getByte(); @@ -115,7 +115,7 @@ private function parseSizeForJPEG() { $state = 'skipframe'; } elseif ( in_array( $b, array_merge( range( 0xC0,0xC3 ), range( 0xC5,0xC7 ), range( 0xC9,0xCB ), range( 0xCD,0xCF ) ), true ) ) { $state = 'readsize'; - } elseif ( $b === 0xFF ) { + } elseif ( 0xFF === $b ) { $state = 'sof'; } else { $state = 'skipframe'; @@ -140,7 +140,7 @@ private function getChars( $n ) { // do we need more data? if ( $this->strpos + $n -1 >= strlen( $this->str ) ) { $end = ($this->strpos + $n); - while ( strlen( $this->str ) < $end && $response !== false ) { + while ( strlen( $this->str ) < $end && false !== $response ) { // read more from the file handle $need = $end - ftell( $this->handle ); if ( $response = fread( $this->handle, $need ) ) { diff --git a/includes/sanitizers/class-amp-blacklist-sanitizer.php b/includes/sanitizers/class-amp-blacklist-sanitizer.php index 6574e2e8e29..a15bf7972d6 100644 --- a/includes/sanitizers/class-amp-blacklist-sanitizer.php +++ b/includes/sanitizers/class-amp-blacklist-sanitizer.php @@ -28,7 +28,7 @@ public function sanitize() { } private function strip_attributes_recursive( $node, $bad_attributes, $bad_protocols ) { - if ( $node->nodeType !== XML_ELEMENT_NODE ) { + if ( XML_ELEMENT_NODE !== $node->nodeType ) { return; } @@ -55,7 +55,7 @@ private function strip_attributes_recursive( $node, $bad_attributes, $bad_protoc } // on* attributes (like onclick) are a special case - if ( 0 === stripos( $attribute_name, 'on' ) && $attribute_name !== 'on' ) { + if ( 0 === stripos( $attribute_name, 'on' ) && 'on' !== $attribute_name ) { $node->removeAttribute( $attribute_name ); continue; } elseif ( 'a' === $node_name ) { diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 86faf50bbea..5953455a1b2 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -18,7 +18,7 @@ public function sanitize() { } private function collect_styles_recursive( $node ) { - if ( $node->nodeType !== XML_ELEMENT_NODE ) { + if ( XML_ELEMENT_NODE !== $node->nodeType ) { return; } diff --git a/includes/utils/class-amp-string-utils.php b/includes/utils/class-amp-string-utils.php index a9e5313b22b..8ab932e4fa5 100644 --- a/includes/utils/class-amp-string-utils.php +++ b/includes/utils/class-amp-string-utils.php @@ -4,6 +4,6 @@ class AMP_String_Utils { public static function endswith( $haystack, $needle ) { return '' !== $haystack && '' !== $needle - && $needle === substr( $haystack, -strlen( $needle ) ); + && substr( $haystack, -strlen( $needle ) ) === $needle; } }