Skip to content

Commit

Permalink
Fix PHPCS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed May 5, 2023
1 parent 8172651 commit f39ed99
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
9 changes: 5 additions & 4 deletions php/WP_CLI/Bootstrap/IncludeRequestsAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ public function process( BootstrapState $state ) {
* across multiple Requests versions.
*
* @param string $class_name The class name of the Requests integration.
* @param string $source The source of the Requests integration.
* @param string $source The source of the Requests integration.
*/
private function store_requests_meta( $class_name, $source ) {
RequestsLibrary::set_version( $class_name === RequestsLibrary::CLASS_NAME_V2
? RequestsLibrary::VERSION_V2
: RequestsLibrary::VERSION_V1
RequestsLibrary::set_version(
RequestsLibrary::CLASS_NAME_V2 === $class_name
? RequestsLibrary::VERSION_V2
: RequestsLibrary::VERSION_V1
);
RequestsLibrary::set_source( $source );
RequestsLibrary::set_class_name( $class_name );
Expand Down
9 changes: 5 additions & 4 deletions php/WP_CLI/RequestsLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class RequestsLibrary {
*
* @var string
*/
const SOURCE_WP_CLI = 'wp-cli';
const SOURCE_WP_CLI = 'wp-cli';

/**
* Array of valid source for the Requests library.
Expand Down Expand Up @@ -223,12 +223,13 @@ public static function set_source( $source ) {
* Check if a given exception was issued by the Requests library.
*
* This is used because we cannot easily catch multiple different exception
* classes with PHP 5.6. Because of that, we catch generic exceptions, check if they match with
* classes with PHP 5.6. Because of that, we catch generic exceptions, check if
* they match the Requests library, and re-throw them if they do not.
*
* @param Exception $exception Exception to check.
* @return bool Whether the provided exception was issued by the Requests library.
*/
public static function isRequestsException( Exception $exception ) {
public static function is_requests_exception( Exception $exception ) {
return is_a( $exception, '\Requests_Exception' )
|| is_a( $exception, '\WpOrg\Requests\Exception' );
}
Expand All @@ -240,7 +241,7 @@ public static function isRequestsException( Exception $exception ) {
* autoloader if it is still needed.
*/
public static function register_autoloader() {
if ( self::is_v1() && ! class_exists ( self::CLASS_NAME_V1 ) ) {
if ( self::is_v1() && ! class_exists( self::CLASS_NAME_V1 ) ) {
if ( self::is_core() ) {
require_once ABSPATH . WPINC . '/class-requests.php';
} else {
Expand Down
2 changes: 1 addition & 1 deletion php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private static function extract_subdir_path( $index_path ) {
*/
public function find_wp_root() {
static $wp_root = null;
if ( $wp_root !== null ) {
if ( null !== $wp_root ) {
return $wp_root;
}

Expand Down
10 changes: 5 additions & 5 deletions php/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,23 +762,23 @@ function http_request( $method, $url, $data = null, $headers = [], $options = []
try {
return $request_method( $url, $headers, $data, $method, $options );
} catch ( Exception $exception ) {
if ( RequestsLibrary::isRequestsException( $exception ) ) {
if ( RequestsLibrary::is_requests_exception( $exception ) ) {
if (
true !== $options['verify']
|| 'curlerror' !== $exception->getType()
|| curl_errno( $exception->getData() ) !== CURLE_SSL_CACERT
) {
throw $exception;
}

$options['verify'] = get_default_cacert( $halt_on_error );

return $request_method( $url, $headers, $data, $method, $options );
}
throw $exception;
}
} catch ( Exception $exception ) {
if ( RequestsLibrary::isRequestsException( $exception ) ) {
if ( RequestsLibrary::is_requests_exception( $exception ) ) {
// CURLE_SSL_CACERT_BADFILE only defined for PHP >= 7.
if (
! $insecure
Expand Down Expand Up @@ -807,7 +807,7 @@ function http_request( $method, $url, $data = null, $headers = [], $options = []
try {
return $request_method( $url, $headers, $data, $method, $options );
} catch ( Exception $exception ) {
if ( RequestsLibrary::isRequestsException( $exception ) ) {
if ( RequestsLibrary::is_requests_exception( $exception ) ) {
$error_msg = sprintf( "Failed to get non-verified url '%s' %s.", $url, $exception->getMessage() );
if ( $halt_on_error ) {
WP_CLI::error( $error_msg );
Expand Down

0 comments on commit f39ed99

Please sign in to comment.