Skip to content

Commit

Permalink
Merge branch 'develop' into 946-remove-part_of_speech-duplicate-block
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrett Hyder committed Oct 15, 2018
2 parents 9146c38 + e8c730b commit dcfe60d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 21 deletions.
78 changes: 62 additions & 16 deletions gp-includes/misc.php
Expand Up @@ -159,39 +159,85 @@ function gp_populate_notices() {
* each of the argument arrays. The returned array is truncated in length to the length
* of the shortest argument array.
*
* The function works only with numerical arrays.
* Previously this function was documented as:
*
* The function works only with numerical arrays.
*
* However this was incorrect, this function would only return an array of arrays with
* numeric basic indexes, but would process any array whether it was numeric or reference
* based, using the order in which the array was created as the index value to return.
*
* For example:
*
* $first_array[] = "First"
* $first_array[] = "Second"
* $first_array[] = "Third"
*
* $second_array[0] = "Fourth"
* $second_array[test] = "Fifth"
* $second_array[1] = "Sixth"
*
* $result = gp_array_zip( $first_array, $second_array );
*
* Would produce:
*
* $result[0][0] = "First"
* $result[0][1] = "Fourth"
* $result[1][0] = "Second"
* $result[1][1] = "Fifth"
* $result[2][0] = "Third"
* $result[2][1] = "Sixth"
*
* Instead of either failing (which is probably what should have happened) or something like:
*
* $result[0][0] = "First"
* $result[0][1] = "Fourth"
* $result[1][0] = "Second"
* $result[1][1] = "Sixth"
*
* Or some other random result.
*
*/
function gp_array_zip() {
$args = func_get_args();

if ( !is_array( $args ) ) {
return false;
}

if ( empty( $args ) ) {
return array();
}
$res = array();

$depth = 0;

foreach ( $args as &$array ) {
if ( !is_array( $array) ) {
return false;
}

$array_size = count( $array );
reset( $array );
}
$all_have_more = true;
while (true) {
$this_round = array();
foreach ( $args as &$array ) {
$all_have_more = ( list( , $value ) = each( $array ) );
if ( !$all_have_more ) {
break;
}
$this_round[] = $value;

if ( 0 === $depth || $depth > $array_size ) {
$depth = $array_size;
}
if ( $all_have_more ) {
$res[] = $this_round;
} else {
break;
}

$res = array();

$array_count = 0;

foreach ( $args as &$array ) {
for ( $i = 0; $i < $depth; $i++ ) {
$res[ $i ][ $array_count ] = current( $array );

next( $array );
}

$array_count++;
}

return $res;
}

Expand Down
2 changes: 1 addition & 1 deletion gp-includes/routes/profile.php
Expand Up @@ -40,7 +40,7 @@ public function profile_view( $user = '' ) {
$user = get_user_by( 'slug', $user );
}

if ( ! $user ) {
if ( ! $user || ( is_object( $user ) && $user instanceof WP_User && ! $user->exists() ) ) {
return $this->die_with_404();
}

Expand Down
6 changes: 5 additions & 1 deletion tests/phpunit/lib/testcase-request.php
Expand Up @@ -22,7 +22,11 @@ private function request( $uri, $method, $vars ) {
'uri' => $uri,
'gp_config_path' => dirname( __FILE__ ) . '/../unittests-config.php',
);
extract( array_map( create_function( '$value', 'return var_export( $value, true );' ), $config_vars ) );
extract( array_map( function( $value ) {
return var_export( $value, true );
},
$config_vars )
);
$config_php_code = <<<CONFIG
<?php
\$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
Expand Down
8 changes: 6 additions & 2 deletions tests/phpunit/testcases/test_warnings.php
Expand Up @@ -3,8 +3,12 @@
class GP_Test_Translation_Warnings extends GP_UnitTestCase {
function setUp() {
parent::setUp();
$this->is_baba = create_function('$o, $t, $l', 'return $t == "баба"? true : "error";');
$this->is_equal = create_function('$o, $t, $l', 'return $t == $o? true : "error";');
$this->is_baba = function( $o, $t, $l ) {
return $t == "баба"? true : "error";
};
$this->is_equal = function( $o, $t, $l ) {
return $t == $o? true : "error";
};
$this->w = new GP_Translation_Warnings;
$this->with_equal = new GP_Translation_Warnings;
$this->with_equal->add( 'is_equal', $this->is_equal );
Expand Down
4 changes: 3 additions & 1 deletion tests/phpunit/testcases/tests_testlib/test_factory.php
Expand Up @@ -118,7 +118,9 @@ private function create_thing_mock_with_name_field_and_with_create_which_should_

function test_factory_for_thing_create_should_use_function_generator() {
$generation_defintions = array(
'full_name' => GP_UnitTest_Factory_For_Thing::callback( create_function( '$o', 'return $o->name . " baba";' ) ),
'full_name' => GP_UnitTest_Factory_For_Thing::callback( function( $o ) {
return $o->name . " baba";
} ),
);
$factory = $this->create_factory( null, $generation_defintions );
$create_args = array('name' => 'my name is');
Expand Down

0 comments on commit dcfe60d

Please sign in to comment.