| Total Complexity | 9 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 8 | class CreateSitecTranslationsData extends Migration |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Run the migrations. |
||
| 13 | * |
||
| 14 | * @return void |
||
| 15 | */ |
||
| 16 | public function up() |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Carrega Paises |
||
| 20 | */ |
||
| 21 | try { |
||
| 22 | $langs = \Illuminate\Support\Facades\Config::get('translation.countries', [ |
||
| 23 | "BR" => "Brazil", |
||
| 24 | ]); |
||
| 25 | if (!empty($langs)) { |
||
| 26 | $class = \Illuminate\Support\Facades\Config::get('translation.models.country', \Translation\Models\Country::class); |
||
| 27 | foreach ($langs as $code=>$name) { |
||
| 28 | $language = new $class; |
||
| 29 | $language->name = $name; |
||
| 30 | $language->code = $code; |
||
| 31 | $language->save(); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | } catch (\Throwable $th) { |
||
| 35 | //throw $th; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Carrega Linguagens |
||
| 40 | */ |
||
| 41 | try { |
||
| 42 | $langs = \Illuminate\Support\Facades\Config::get('translation.locales', [ |
||
| 43 | 'pt' => 'Portuguese', |
||
| 44 | ]); |
||
| 45 | if (!empty($langs)) { |
||
| 46 | $class = \Illuminate\Support\Facades\Config::get('translation.models.language', \Translation\Models\Language::class); |
||
| 47 | foreach ($langs as $code=>$name) { |
||
| 48 | $language = new $class; |
||
| 49 | $language->name = $name; |
||
| 50 | $language->code = $code; |
||
| 51 | $language->save(); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } catch (\Throwable $th) { |
||
| 55 | //throw $th; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Localizações principais Principais |
||
| 60 | */ |
||
| 61 | try { |
||
| 62 | $class = \Illuminate\Support\Facades\Config::get('translation.models.locale', \Translation\Models\Locale::class); |
||
| 63 | $locale = new $class; |
||
| 64 | $locale->country_code = 'BR'; |
||
| 65 | $locale->language_code = 'pt'; |
||
| 66 | $locale->save(); |
||
| 67 | } catch (\Throwable $th) { |
||
| 68 | //throw $th; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Reverse the migrations. |
||
| 74 | * |
||
| 75 | * @return void |
||
| 76 | */ |
||
| 77 | public function down() |
||
| 79 | |||
| 80 | } |
||
| 82 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: