| Conditions | 5 |
| Paths | 4 |
| Total Lines | 108 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 15 | public function up() |
||
| 16 | { |
||
| 17 | Schema::create('countries', function (Blueprint $table) { |
||
| 18 | $table->string('code')->unique(); |
||
| 19 | $table->primary('code'); |
||
| 20 | $table->string('name'); |
||
| 21 | }); |
||
| 22 | |||
| 23 | Schema::create('languages', function (Blueprint $table) { |
||
| 24 | $table->engine = 'InnoDB'; |
||
| 25 | $table->string('code')->unique(); |
||
| 26 | $table->primary('code'); |
||
| 27 | |||
| 28 | $table->integer('position')->nullable(); |
||
| 29 | $table->string('name', 50); |
||
| 30 | }); |
||
| 31 | |||
| 32 | Schema::create('locales', function (Blueprint $table) { |
||
| 33 | $table->string('language')->unique(); |
||
| 34 | $table->string('country')->nullable(); |
||
| 35 | |||
| 36 | $table->primary(['language','country']); |
||
| 37 | |||
| 38 | $table->foreign('language')->references('code')->on('languages'); |
||
| 39 | $table->foreign('country')->references('code')->on('countries'); |
||
| 40 | |||
| 41 | }); |
||
| 42 | |||
| 43 | |||
| 44 | Schema::create('translations', function (Blueprint $table) { |
||
| 45 | $table->increments('id'); |
||
| 46 | $table->string('locale', 10); |
||
| 47 | $table->string('namespace')->default('*'); |
||
| 48 | $table->string('group'); |
||
| 49 | $table->string('item'); |
||
| 50 | $table->text('text'); |
||
| 51 | $table->boolean('unstable')->default(false); |
||
| 52 | $table->boolean('locked')->default(false); |
||
| 53 | |||
| 54 | $table->foreign('locale')->references('code')->on('languages'); |
||
| 55 | $table->unique(['locale', 'namespace', 'group', 'item']); |
||
| 56 | |||
| 57 | $table->timestamps(); |
||
| 58 | $table->softDeletes(); |
||
| 59 | }); |
||
| 60 | |||
| 61 | // Schema::create('translations', function (Blueprint $table) { |
||
| 62 | // $table->increments('id'); |
||
| 63 | // $table->timestamps(); |
||
| 64 | // $table->integer('locale_id')->unsigned(); |
||
| 65 | // $table->integer('translation_id')->unsigned()->nullable(); |
||
| 66 | // $table->text('translation'); |
||
| 67 | |||
| 68 | // $table->foreign('locale_id')->references('id')->on('locales') |
||
| 69 | // ->onUpdate('restrict') |
||
| 70 | // ->onDelete('cascade'); |
||
| 71 | |||
| 72 | // $table->foreign('translation_id')->references('id')->on('translations') |
||
| 73 | // ->onUpdate('restrict') |
||
| 74 | // ->onDelete('cascade'); |
||
| 75 | // }); |
||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | Schema::create(config('app.db-prefix', '').'locations', function (Blueprint $table) { |
||
| 80 | $table->increments('id'); |
||
| 81 | }); |
||
| 82 | |||
| 83 | // Note: Laravel does not support spatial types. |
||
| 84 | // See: https://dev.mysql.com/doc/refman/5.7/en/spatial-type-overview.html |
||
| 85 | DB::statement("ALTER TABLE `locations` ADD `coordinates` POINT;"); |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Carrega Paises |
||
| 89 | */ |
||
| 90 | $langs = config('translation.countries'); |
||
| 91 | if (!empty($langs)) { |
||
| 92 | $class = config('translation.models.country'); |
||
| 93 | foreach($langs as $code=>$name) { |
||
| 94 | $language = new $class; |
||
| 95 | $language->name = $name; |
||
| 96 | $language->code = $code; |
||
| 97 | $language->save(); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Carrega Linguagens |
||
| 103 | */ |
||
| 104 | $langs = config('translation.locales'); |
||
| 105 | if (!empty($langs)) { |
||
| 106 | $class = config('translation.models.language'); |
||
| 107 | foreach($langs as $code=>$name) { |
||
| 108 | $language = new $class; |
||
| 109 | $language->name = $name; |
||
| 110 | $language->code = $code; |
||
| 111 | $language->save(); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Localizações principais Principais |
||
| 117 | */ |
||
| 118 | $class = config('translation.models.locale'); |
||
| 119 | $locale = new $class; |
||
| 120 | $locale->country = 'BR'; |
||
| 121 | $locale->language = 'pt'; |
||
| 122 | $locale->save(); |
||
| 123 | } |
||
| 138 |