CreateSitecTranslationsData::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 0
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
4
use Illuminate\Database\Migrations\Migration;
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Support\Facades\Schema;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Schema. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are 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.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
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()
78
    {
79
        
80
    }
81
}
82