| Conditions | 9 |
| Paths | 20 |
| Total Lines | 51 |
| Lines | 18 |
| Ratio | 35.29 % |
| 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 |
||
| 42 | public function handle() |
||
| 43 | { |
||
| 44 | $connection = Config::get('ab::connection'); |
||
| 45 | |||
| 46 | // Create experiments table. |
||
| 47 | View Code Duplication | if (! Schema::connection($connection)->hasTable('experiments')) { |
|
| 48 | Schema::connection($connection)->create('experiments', function ($table) { |
||
| 49 | $table->increments('id'); |
||
| 50 | $table->string('name'); |
||
| 51 | $table->integer('visitors')->unsigned()->default(0); |
||
| 52 | $table->integer('engagement')->unsigned()->default(0); |
||
| 53 | $table->timestamps(); |
||
| 54 | }); |
||
| 55 | } |
||
| 56 | |||
| 57 | // Create goals table. |
||
| 58 | View Code Duplication | if (! Schema::connection($connection)->hasTable('goals')) { |
|
| 59 | Schema::connection($connection)->create('goals', function ($table) { |
||
| 60 | $table->increments('id'); |
||
| 61 | $table->string('name'); |
||
| 62 | $table->string('experiment'); |
||
| 63 | $table->integer('count')->unsigned()->default(0); |
||
| 64 | $table->timestamps(); |
||
| 65 | }); |
||
| 66 | } |
||
| 67 | |||
| 68 | $this->info('Database schema initialized.'); |
||
| 69 | |||
| 70 | $experiments = Config::get('ab')['experiments']; |
||
| 71 | |||
| 72 | if (! $experiments or empty($experiments)) { |
||
| 73 | return $this->error('No experiments configured.'); |
||
| 74 | } |
||
| 75 | |||
| 76 | $goals = Config::get('ab')['goals']; |
||
| 77 | |||
| 78 | if (! $goals or empty($goals)) { |
||
| 79 | return $this->error('No goals configured.'); |
||
| 80 | } |
||
| 81 | |||
| 82 | // Populate experiments and goals. |
||
| 83 | foreach ($experiments as $experiment) { |
||
| 84 | Experiment::firstOrCreate(['name' => $experiment]); |
||
| 85 | |||
| 86 | foreach ($goals as $goal) { |
||
| 87 | Goal::firstOrCreate(['name' => $goal, 'experiment' => $experiment]); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | $this->info('Added '.count($experiments).' experiments.'); |
||
| 92 | } |
||
| 93 | |||
| 114 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.