Conditions | 8 |
Paths | 196 |
Total Lines | 52 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
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; |
||
82 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/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 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: