phpcs lint fixes

This commit is contained in:
Alex Kirk 2022-12-09 09:28:00 +01:00
parent 0230cf7d70
commit 7ebb89e92e
5 changed files with 16 additions and 16 deletions

View file

@ -21,15 +21,15 @@ class Hashtag {
* Filter to save #tags as real WordPress tags * Filter to save #tags as real WordPress tags
* *
* @param int $id the rev-id * @param int $id the rev-id
* @param array $data the post-data as array * @param WP_Post $post the post
* *
* @return * @return
*/ */
public static function insert_post( $id, $data ) { public static function insert_post( $id, $post ) {
if ( \preg_match_all( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', $data->post_content, $match ) ) { if ( \preg_match_all( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', $post->post_content, $match ) ) {
$tags = \implode( ', ', $match[1] ); $tags = \implode( ', ', $match[1] );
\wp_add_post_tags( $data->post_parent, $tags ); \wp_add_post_tags( $post->post_parent, $tags );
} }
return $id; return $id;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -74,7 +74,7 @@ class Test_Activitypub_Activity_Dispatcher extends WP_UnitTestCase {
return $in; return $in;
} }
public static function http_request_args( $args, $url ) { public static function http_request_args( $args, $url ) {
if ( in_array( parse_url( $url, PHP_URL_HOST ), array( 'example.com', 'example.org' ), true ) ) { if ( in_array( wp_parse_url( $url, PHP_URL_HOST ), array( 'example.com', 'example.org' ), true ) ) {
$args['reject_unsafe_urls'] = false; $args['reject_unsafe_urls'] = false;
} }
return $args; return $args;

View file

@ -22,7 +22,7 @@ class Test_Friends_Feed_Parser_ActivityPub extends \WP_UnitTestCase {
// Let's post a new Note through the REST API. // Let's post a new Note through the REST API.
$date = gmdate( \DATE_W3C, $now++ ); $date = gmdate( \DATE_W3C, $now++ );
$id = 'test' . $status_id; $id = 'test' . $status_id;
$content = 'Test ' . $date . ' ' . rand(); $content = 'Test ' . $date . ' ' . wp_rand();
$request = new \WP_REST_Request( 'POST', '/activitypub/1.0/users/' . get_current_user_id() . '/inbox' ); $request = new \WP_REST_Request( 'POST', '/activitypub/1.0/users/' . get_current_user_id() . '/inbox' );
$request->set_param( 'type', 'Create' ); $request->set_param( 'type', 'Create' );
@ -74,7 +74,7 @@ class Test_Friends_Feed_Parser_ActivityPub extends \WP_UnitTestCase {
// Do another test post, this time with a URL that has an @-id. // Do another test post, this time with a URL that has an @-id.
$date = gmdate( \DATE_W3C, $now++ ); $date = gmdate( \DATE_W3C, $now++ );
$id = 'test' . $status_id; $id = 'test' . $status_id;
$content = 'Test ' . $date . ' ' . rand(); $content = 'Test ' . $date . ' ' . wp_rand();
$request = new \WP_REST_Request( 'POST', '/activitypub/1.0/users/' . get_current_user_id() . '/inbox' ); $request = new \WP_REST_Request( 'POST', '/activitypub/1.0/users/' . get_current_user_id() . '/inbox' );
$request->set_param( 'type', 'Create' ); $request->set_param( 'type', 'Create' );
@ -142,10 +142,10 @@ class Test_Friends_Feed_Parser_ActivityPub extends \WP_UnitTestCase {
$this->assertEquals( 202, $response->get_status() ); $this->assertEquals( 202, $response->get_status() );
$p = wp_parse_url( $object ); $p = wp_parse_url( $object );
$cache = __DIR__ . '/fixtures/' . sanitize_title( $p['host'] . '-' . $p['path'] ) . '.response'; $cache = __DIR__ . '/fixtures/' . sanitize_title( $p['host'] . '-' . $p['path'] ) . '.json';
$this->assertFileExists( $cache ); $this->assertFileExists( $cache );
$object = json_decode( wp_remote_retrieve_body( unserialize( file_get_contents( $cache ) ) ) ); $object = json_decode( wp_remote_retrieve_body( json_decode( file_get_contents( $cache ), true ) ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$posts = get_posts( $posts = get_posts(
array( array(
@ -244,18 +244,18 @@ class Test_Friends_Feed_Parser_ActivityPub extends \WP_UnitTestCase {
return $in; return $in;
} }
public static function http_request_args( $args, $url ) { public static function http_request_args( $args, $url ) {
if ( in_array( parse_url( $url, PHP_URL_HOST ), array( 'mastodon.local' ), true ) ) { if ( in_array( wp_parse_url( $url, PHP_URL_HOST ), array( 'mastodon.local' ), true ) ) {
$args['reject_unsafe_urls'] = false; $args['reject_unsafe_urls'] = false;
} }
return $args; return $args;
} }
public static function pre_http_request( $preempt, $request, $url ) { public static function pre_http_request( $preempt, $request, $url ) {
$p = wp_parse_url( $url ); $p = wp_parse_url( $url );
$cache = __DIR__ . '/fixtures/' . sanitize_title( $p['host'] . '-' . $p['path'] ) . '.response'; $cache = __DIR__ . '/fixtures/' . sanitize_title( $p['host'] . '-' . $p['path'] ) . '.json';
if ( file_exists( $cache ) ) { if ( file_exists( $cache ) ) {
return apply_filters( return apply_filters(
'fake_http_response', 'fake_http_response',
unserialize( file_get_contents( $cache ) ), json_decode( file_get_contents( $cache ), true ), // phpcs:ignore
$p['scheme'] . '://' . $p['host'], $p['scheme'] . '://' . $p['host'],
$url, $url,
$request $request
@ -305,12 +305,12 @@ class Test_Friends_Feed_Parser_ActivityPub extends \WP_UnitTestCase {
public static function http_response( $response, $args, $url ) { public static function http_response( $response, $args, $url ) {
$p = wp_parse_url( $url ); $p = wp_parse_url( $url );
$cache = __DIR__ . '/fixtures/' . sanitize_title( $p['host'] . '-' . $p['path'] ) . '.response'; $cache = __DIR__ . '/fixtures/' . sanitize_title( $p['host'] . '-' . $p['path'] ) . '.json';
if ( ! file_exists( $cache ) ) { if ( ! file_exists( $cache ) ) {
$headers = wp_remote_retrieve_headers( $response ); $headers = wp_remote_retrieve_headers( $response );
file_put_contents( file_put_contents( // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
$cache, $cache,
serialize( wp_json_encode(
array( array(
'headers' => $headers->getAll(), 'headers' => $headers->getAll(),
'body' => wp_remote_retrieve_body( $response ), 'body' => wp_remote_retrieve_body( $response ),