Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of create_function so PHP 7.2 does not complain #8478

Merged
merged 2 commits into from
Jan 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 40 additions & 8 deletions tests/php/sync/server/class.jetpack-sync-test-replicastore.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,25 @@ public function get_metadata( $type, $object_id, $meta_key = '', $single = false

// this is just here to support checksum histograms
function get_post_meta_by_id( $meta_id ) {
$matching_metas = array_filter( $this->meta[ get_current_blog_id() ][ 'post' ], create_function( '$m', 'return $m->meta_id == '.$meta_id.';' ) );
$matching_metas = array();
$metas = $this->meta[ get_current_blog_id() ]['post'];
foreach ( $metas as $m ) {
if ( $m->meta_id === $meta_id ) {
$matching_metas[] = $m;
}
}
return reset( $matching_metas );
}

// this is just here to support checksum histograms
function get_comment_meta_by_id( $meta_id ) {
$matching_metas = array_filter( $this->meta[ get_current_blog_id() ][ 'comment' ], create_function( '$m', 'return $m->meta_id == '.$meta_id.';' ) );
$matching_metas = array();
$metas = $this->meta[ get_current_blog_id() ]['comment'];
foreach ( $metas as $m ) {
if ( $m->meta_id === $meta_id ) {
$matching_metas[] = $m;
}
}
return reset( $matching_metas );
}

Expand Down Expand Up @@ -559,12 +571,32 @@ function checksum_all() {
);
}

function object_id( $o ) {
return $o->ID;
}

function is_comment( $m ) {
return 'comment' === $m->type;
}

function is_post( $m ) {
return 'post' === $m->type;
}

function comment_id( $o ) {
return $o->comment_ID;
}

function meta_id( $o ) {
return $o->meta_id;
}

function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id = null, $fields = null ) {
// divide all IDs into the number of buckets
switch ( $object_type ) {
case 'posts':
$posts = $this->get_posts( null, $start_id, $end_id );
$all_ids = array_map( create_function( '$o', 'return $o->ID;' ), $posts );
$all_ids = array_map( array( $this, 'object_id' ), $posts );
$id_field = 'ID';
$get_function = 'get_post';

Expand All @@ -574,8 +606,8 @@ function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id =

break;
case 'post_meta':
$post_meta = array_filter( $this->meta[ get_current_blog_id() ][ 'post' ], create_function( '$m', 'return $m->type === \'post\';' ) );
$all_ids = array_values( array_map( create_function( '$o', 'return $o->meta_id;' ), $post_meta ) );
$post_meta = array_filter( $this->meta[ get_current_blog_id() ]['post'], array( $this, 'is_post' ) );
$all_ids = array_values( array_map( array( $this, 'meta_id' ), $post_meta ) );
$id_field = 'meta_id';
$get_function = 'get_post_meta_by_id';

Expand All @@ -585,7 +617,7 @@ function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id =
break;
case 'comments':
$comments = $this->get_comments( null, $start_id, $end_id );
$all_ids = array_map( create_function( '$o', 'return $o->comment_ID;' ), $comments );
$all_ids = array_map( array( $this, 'comment_id' ), $comments );
$id_field = 'comment_ID';
$get_function = 'get_comment';

Expand All @@ -594,8 +626,8 @@ function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id =
}
break;
case 'comment_meta':
$comment_meta = array_filter( $this->meta[ get_current_blog_id() ][ 'comment' ], create_function( '$m', 'return $m->type === \'comment\';' ) );
$all_ids = array_values( array_map( create_function( '$o', 'return $o->meta_id;' ), $comment_meta ) );
$comment_meta = array_filter( $this->meta[ get_current_blog_id() ]['comment'], array( $this, 'is_comment' ) );
$all_ids = array_values( array_map( array( $this, 'meta_id' ), $comment_meta ) );
$id_field = 'meta_id';
$get_function = 'get_comment_meta_by_id';

Expand Down