| Conditions | 5 |
| Paths | 12 |
| Total Lines | 103 |
| Code Lines | 77 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 90 | public function getSetup() |
||
| 91 | { |
||
| 92 | Schema::dropIfExists('demo_users'); |
||
| 93 | Schema::dropIfExists('demo_articles'); |
||
| 94 | Schema::dropIfExists('demo_article_detail'); |
||
| 95 | Schema::dropIfExists('demo_comments'); |
||
| 96 | Schema::dropIfExists('demo_categories'); |
||
| 97 | Schema::dropIfExists('demo_article_category'); |
||
| 98 | |||
| 99 | //create all tables |
||
| 100 | Schema::table('demo_users', function ($table) { |
||
| 101 | $table->create(); |
||
| 102 | $table->increments('id'); |
||
| 103 | $table->string('firstname', 100); |
||
| 104 | $table->string('lastname', 100); |
||
| 105 | $table->timestamps(); |
||
| 106 | }); |
||
| 107 | Schema::table('demo_articles', function ($table) { |
||
| 108 | $table->create(); |
||
| 109 | $table->increments('id'); |
||
| 110 | $table->integer('author_id')->unsigned(); |
||
| 111 | $table->string('title', 200); |
||
| 112 | $table->text('body'); |
||
| 113 | $table->string('photo', 200); |
||
| 114 | $table->boolean('public'); |
||
| 115 | $table->timestamp('publication_date'); |
||
| 116 | $table->timestamps(); |
||
| 117 | }); |
||
| 118 | Schema::table('demo_article_detail', function ($table) { |
||
| 119 | $table->create(); |
||
| 120 | $table->increments('id'); |
||
| 121 | $table->integer('article_id')->unsigned(); |
||
| 122 | $table->text('note'); |
||
| 123 | $table->string('note_tags', 200); |
||
| 124 | }); |
||
| 125 | Schema::table('demo_comments', function ($table) { |
||
| 126 | $table->create(); |
||
| 127 | $table->increments('id'); |
||
| 128 | $table->integer('user_id')->unsigned(); |
||
| 129 | $table->integer('article_id')->unsigned(); |
||
| 130 | $table->text('comment'); |
||
| 131 | $table->timestamps(); |
||
| 132 | }); |
||
| 133 | Schema::table('demo_categories', function ($table) { |
||
| 134 | $table->create(); |
||
| 135 | $table->increments('id'); |
||
| 136 | $table->integer('parent_id')->unsigned(); |
||
| 137 | $table->string('name', 100); |
||
| 138 | $table->timestamps(); |
||
| 139 | }); |
||
| 140 | Schema::table('demo_article_category', function ($table) { |
||
| 141 | $table->create(); |
||
| 142 | $table->integer('article_id')->unsigned(); |
||
| 143 | $table->integer('category_id')->unsigned(); |
||
| 144 | $table->timestamps(); |
||
| 145 | }); |
||
| 146 | |||
| 147 | //populate all tables |
||
| 148 | $users = DB::table('demo_users'); |
||
| 149 | $users->insert(array('firstname' => 'Jhon', 'lastname' => 'Doe')); |
||
| 150 | $users->insert(array('firstname' => 'Jane', 'lastname' => 'Doe')); |
||
| 151 | |||
| 152 | $categories = DB::table('demo_categories'); |
||
| 153 | for ($i = 1; $i <= 5; ++$i) { |
||
| 154 | $categories->insert(array( |
||
| 155 | 'name' => 'Category '.$i, |
||
| 156 | ) |
||
| 157 | ); |
||
| 158 | } |
||
| 159 | $articles = DB::table('demo_articles'); |
||
| 160 | for ($i = 1; $i <= 20; ++$i) { |
||
| 161 | $articles->insert(array( |
||
| 162 | 'author_id' => rand(1, 2), |
||
| 163 | 'title' => 'Article '.$i, |
||
| 164 | 'body' => 'Body of article '.$i, |
||
| 165 | 'publication_date' => date('Y-m-d'), |
||
| 166 | 'public' => true, |
||
| 167 | ) |
||
| 168 | ); |
||
| 169 | } |
||
| 170 | $categories = DB::table('demo_article_category'); |
||
| 171 | $categories->insert(array('article_id' => 1, 'category_id' => 1)); |
||
| 172 | $categories->insert(array('article_id' => 1, 'category_id' => 2)); |
||
| 173 | $categories->insert(array('article_id' => 20, 'category_id' => 2)); |
||
| 174 | $categories->insert(array('article_id' => 20, 'category_id' => 3)); |
||
| 175 | |||
| 176 | $comments = DB::table('demo_comments'); |
||
| 177 | $comments->insert(array( |
||
| 178 | 'user_id' => 1, |
||
| 179 | 'article_id' => 2, |
||
| 180 | 'comment' => 'Comment for Article 2', |
||
| 181 | ) |
||
| 182 | ); |
||
| 183 | |||
| 184 | $files = glob(public_path().'/uploads/demo/*'); |
||
| 185 | foreach ($files as $file) { |
||
| 186 | if (is_file($file)) { |
||
| 187 | @unlink($file); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | echo 'All set!'; |
||
| 192 | } |
||
| 193 | |||
| 205 |