Conditions | 2 |
Paths | 2 |
Total Lines | 74 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
25 | public function run() |
||
26 | { |
||
27 | // Initializing variables. |
||
28 | $createdAt = date('Y-m-d H:i:s'); |
||
29 | $locations = []; |
||
30 | |||
31 | $tableNames = config('pwweb.localisation.table_names'); |
||
32 | |||
33 | // Definition of default locations. |
||
34 | $locations[] = ['tax_rate_id' => 1, 'country_id' => 'United Kingdom']; |
||
35 | $locations[] = ['tax_rate_id' => 1, 'country_id' => 'Croatia']; |
||
36 | $locations[] = ['tax_rate_id' => 1, 'country_id' => 'Poland']; |
||
37 | $locations[] = ['tax_rate_id' => 1, 'country_id' => 'Lithuania']; |
||
38 | $locations[] = ['tax_rate_id' => 1, 'country_id' => 'Romania']; |
||
39 | $locations[] = ['tax_rate_id' => 1, 'country_id' => 'Cyprus']; |
||
40 | |||
41 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'United Kingdom']; |
||
42 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Hungary']; |
||
43 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Sweden']; |
||
44 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Denmark']; |
||
45 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Poland']; |
||
46 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Ireland']; |
||
47 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Netherlands']; |
||
48 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Latvia']; |
||
49 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Belgium']; |
||
50 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Bulgaria']; |
||
51 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Germany']; |
||
52 | $locations[] = ['tax_rate_id' => 2, 'country_id' => 'Malta']; |
||
53 | |||
54 | $locations[] = ['tax_rate_id' => 3, 'country_id' => ['Luxembourg']]; |
||
55 | |||
56 | $locations[] = ['tax_rate_id' => 4, 'country_id' => ['Malta']]; |
||
57 | |||
58 | $locations[] = ['tax_rate_id' => 5, 'country_id' => 'Cyprus']; |
||
59 | $locations[] = ['tax_rate_id' => 5, 'country_id' => 'Romania']; |
||
60 | $locations[] = ['tax_rate_id' => 5, 'country_id' => 'Germany']; |
||
61 | |||
62 | $locations[] = ['tax_rate_id' => 6, 'country_id' => 'Austria']; |
||
63 | $locations[] = ['tax_rate_id' => 6, 'country_id' => 'Bulgaria']; |
||
64 | $locations[] = ['tax_rate_id' => 6, 'country_id' => 'France']; |
||
65 | $locations[] = ['tax_rate_id' => 6, 'country_id' => 'Slovakia']; |
||
66 | $locations[] = ['tax_rate_id' => 6, 'country_id' => 'Estonia']; |
||
67 | $locations[] = ['tax_rate_id' => 6, 'country_id' => 'United Kingdom']; |
||
68 | |||
69 | $locations[] = ['tax_rate_id' => 7, 'country_id' => 'Belgium']; |
||
70 | $locations[] = ['tax_rate_id' => 7, 'country_id' => 'Czech Republic']; |
||
71 | $locations[] = ['tax_rate_id' => 7, 'country_id' => 'Latvia']; |
||
72 | $locations[] = ['tax_rate_id' => 7, 'country_id' => 'Lithuania']; |
||
73 | $locations[] = ['tax_rate_id' => 7, 'country_id' => 'Netherlands']; |
||
74 | $locations[] = ['tax_rate_id' => 7, 'country_id' => 'Spain']; |
||
75 | |||
76 | $locations[] = ['tax_rate_id' => 8, 'country_id' => 'Slovenia']; |
||
77 | $locations[] = ['tax_rate_id' => 8, 'country_id' => 'Italy']; |
||
78 | |||
79 | $locations[] = ['tax_rate_id' => 9, 'country_id' => 'Ireland']; |
||
80 | $locations[] = ['tax_rate_id' => 9, 'country_id' => 'Poland']; |
||
81 | $locations[] = ['tax_rate_id' => 9, 'country_id' => 'Portugal']; |
||
82 | |||
83 | $locations[] = ['tax_rate_id' => 10, 'country_id' => 'Finland']; |
||
84 | $locations[] = ['tax_rate_id' => 10, 'country_id' => 'Greece']; |
||
85 | |||
86 | $locations[] = ['tax_rate_id' => 11, 'country_id' => 'Croatia']; |
||
87 | $locations[] = ['tax_rate_id' => 11, 'country_id' => 'Denmark']; |
||
88 | $locations[] = ['tax_rate_id' => 11, 'country_id' => 'Sweden']; |
||
89 | |||
90 | $locations[] = ['tax_rate_id' => 12, 'country_id' => 'Hungary']; |
||
91 | |||
92 | foreach ($locations as &$location) { |
||
93 | $country = DB::table($tableNames['countries'])->where('name', $location['country_id'])->first(); |
||
94 | $location['country_id'] = $country->id; |
||
95 | $location = array_merge($location, ['active' => false, 'created_at' => $createdAt, 'updated_at' => $createdAt]); |
||
96 | } |
||
97 | |||
98 | DB::table($tableNames['tax']['locations'])->insert($locations); |
||
99 | } |
||
101 |