Skip to content

Commit

Permalink
use yoda condition checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Schreiber committed Mar 7, 2017
1 parent c6933dd commit ce4867f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions includes/lib/class-faster-image-b52f1a8-faster-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ 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" );
}
}

// 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" );
}

Expand Down
12 changes: 6 additions & 6 deletions includes/lib/class-faster-image-b52f1a8-image-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down Expand Up @@ -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;
Expand All @@ -209,7 +209,7 @@ protected function parseSizeForJPEG() {
$state = 'readsize';
break;
}
if ( $b === 0xFF ) {
if ( 0xFF === $b ) {
$state = 'sof';
break;
}
Expand Down
8 changes: 4 additions & 4 deletions includes/lib/class-fastimage.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ 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();
if ( in_array( $b, range( 0xe0, 0xef ), true ) ) {
$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';
Expand All @@ -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 ) ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/sanitizers/class-amp-blacklist-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/sanitizers/class-amp-style-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/utils/class-amp-string-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit ce4867f

Please sign in to comment.