| Conditions | 1 |
| Paths | 1 |
| Total Lines | 89 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 44 | public static function generate_shared_fixtures( $factory ) { |
||
| 45 | self::$old_current_user = get_current_user_id(); |
||
| 46 | self::$author_id = $factory->user->create( array( 'user_login' => 'canonical-author' ) ); |
||
| 47 | |||
| 48 | /* |
||
| 49 | * Also set in self::setUp(), but we must configure here to make sure that |
||
| 50 | * post authorship is properly attributed for fixtures. |
||
| 51 | */ |
||
| 52 | wp_set_current_user( self::$author_id ); |
||
| 53 | |||
| 54 | // Already created by install defaults: |
||
| 55 | // self::factory()->term->create( array( 'taxonomy' => 'category', 'name' => 'uncategorized' ) ); |
||
| 56 | |||
| 57 | self::$post_ids[] = $factory->post->create( array( 'import_id' => 587, 'post_title' => 'post-format-test-audio', 'post_date' => '2008-06-02 00:00:00' ) ); |
||
| 58 | self::$post_ids[] = $post_id = $factory->post->create( array( 'post_title' => 'post-format-test-gallery', 'post_date' => '2008-06-10 00:00:00' ) ); |
||
| 59 | self::$post_ids[] = $factory->post->create( array( 'import_id' => 611, 'post_type' => 'attachment', 'post_title' => 'canola2', 'post_parent' => $post_id ) ); |
||
| 60 | |||
| 61 | self::$post_ids[] = $factory->post->create( array( |
||
| 62 | 'post_title' => 'images-test', |
||
| 63 | 'post_date' => '2008-09-03 00:00:00', |
||
| 64 | 'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3' |
||
| 65 | ) ); |
||
| 66 | |||
| 67 | self::$post_ids[] = $post_id = $factory->post->create( array( 'import_id' => 149, 'post_title' => 'comment-test', 'post_date' => '2008-03-03 00:00:00' ) ); |
||
| 68 | self::$comment_ids = $factory->comment->create_post_comments( $post_id, 15 ); |
||
| 69 | |||
| 70 | self::$post_ids[] = $factory->post->create( array( 'post_date' => '2008-09-05 00:00:00' ) ); |
||
| 71 | |||
| 72 | self::$post_ids[] = $factory->post->create( array( 'import_id' => 123 ) ); |
||
| 73 | self::$post_ids[] = $factory->post->create( array( 'import_id' => 1 ) ); |
||
| 74 | self::$post_ids[] = $factory->post->create( array( 'import_id' => 358 ) ); |
||
| 75 | |||
| 76 | self::$post_ids[] = $factory->post->create( array( 'post_type' => 'page', 'post_title' => 'sample-page' ) ); |
||
| 77 | self::$post_ids[] = $factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about' ) ); |
||
| 78 | self::$post_ids[] = $post_id = $factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) ); |
||
| 79 | self::$post_ids[] = $factory->post->create( |
||
| 80 | array( 'import_id' => 144, 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $post_id, |
||
| 81 | ) ); |
||
| 82 | |||
| 83 | self::$post_ids[] = $parent_id = $factory->post->create( array( |
||
| 84 | 'post_name' => 'parent', |
||
| 85 | 'post_type' => 'page', |
||
| 86 | ) ); |
||
| 87 | self::$post_ids[] = $child_id_1 = $factory->post->create( array( |
||
| 88 | 'post_name' => 'child1', |
||
| 89 | 'post_type' => 'page', |
||
| 90 | 'post_parent' => $parent_id, |
||
| 91 | ) ); |
||
| 92 | self::$post_ids[] = $child_id_2 = $factory->post->create( array( |
||
| 93 | 'post_name' => 'child2', |
||
| 94 | 'post_type' => 'page', |
||
| 95 | 'post_parent' => $parent_id, |
||
| 96 | ) ); |
||
| 97 | self::$post_ids[] = $grandchild_id_1 = $factory->post->create( array( |
||
|
|
|||
| 98 | 'post_name' => 'grandchild', |
||
| 99 | 'post_type' => 'page', |
||
| 100 | 'post_parent' => $child_id_1, |
||
| 101 | ) ); |
||
| 102 | self::$post_ids[] = $grandchild_id_2 = $factory->post->create( array( |
||
| 103 | 'post_name' => 'grandchild', |
||
| 104 | 'post_type' => 'page', |
||
| 105 | 'post_parent' => $child_id_2, |
||
| 106 | ) ); |
||
| 107 | |||
| 108 | $cat1 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'parent' ) ); |
||
| 109 | self::$terms['/category/parent/'] = $cat1; |
||
| 110 | self::$term_ids[ $cat1 ] = 'category'; |
||
| 111 | |||
| 112 | $cat2 = $factory->term->create( array( |
||
| 113 | 'taxonomy' => 'category', 'name' => 'child-1', 'parent' => self::$terms['/category/parent/'], |
||
| 114 | ) ); |
||
| 115 | self::$terms['/category/parent/child-1/'] = $cat2; |
||
| 116 | self::$term_ids[ $cat2 ] = 'category'; |
||
| 117 | |||
| 118 | $cat3 = $factory->term->create( array( |
||
| 119 | 'taxonomy' => 'category', 'name' => 'child-2', 'parent' => self::$terms['/category/parent/child-1/'], |
||
| 120 | ) ); |
||
| 121 | self::$terms['/category/parent/child-1/child-2/'] = $cat3; |
||
| 122 | self::$term_ids[ $cat3 ] = 'category'; |
||
| 123 | |||
| 124 | $cat4 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) ); |
||
| 125 | self::$term_ids[ $cat4 ] = 'category'; |
||
| 126 | |||
| 127 | $cat5 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) ); |
||
| 128 | self::$term_ids[ $cat5 ] = 'category'; |
||
| 129 | |||
| 130 | $tag1 = $factory->term->create( array( 'name' => 'post-formats' ) ); |
||
| 131 | self::$term_ids[ $tag1 ] = 'post_tag'; |
||
| 132 | } |
||
| 133 | |||
| 222 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.