Conditions | 19 |
Paths | 729 |
Total Lines | 94 |
Code Lines | 66 |
Lines | 82 |
Ratio | 87.23 % |
Changes | 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 |
||
5 | public function run($request) { |
||
6 | View Code Duplication | $log = function($message) { |
|
7 | $message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message; |
||
8 | echo $message . PHP_EOL; |
||
9 | }; |
||
10 | |||
11 | $count = 0; |
||
12 | |||
13 | View Code Duplication | foreach (DNEnvironment::get() as $environment) { |
|
14 | $project = $environment->Project(); |
||
15 | if (!$project || !$project->exists()) { |
||
16 | $log(sprintf( |
||
17 | 'Environment (ID %s, Created: %s) is linked to a non-existent project. Deleting', |
||
18 | $environment->ID, |
||
19 | $environment->Created |
||
20 | )); |
||
21 | $environment->delete(); |
||
22 | $environment->destroy(); |
||
23 | $count++; |
||
24 | } |
||
25 | } |
||
26 | |||
27 | View Code Duplication | foreach (DNDeployment::get() as $deployment) { |
|
28 | $environment = $deployment->Environment(); |
||
29 | if (!$environment || !$environment->exists()) { |
||
30 | $log(sprintf( |
||
31 | 'Deployment (ID %s, Created: %s) is linked to a non-existent environment. Deleting', |
||
32 | $deployment->ID, |
||
33 | $deployment->Created |
||
34 | )); |
||
35 | $deployment->delete(); |
||
36 | $deployment->destroy(); |
||
37 | $count++; |
||
38 | } |
||
39 | } |
||
40 | |||
41 | View Code Duplication | foreach (DNDataTransfer::get() as $transfer) { |
|
42 | $environment = $transfer->Environment(); |
||
43 | if (!$environment || !$environment->exists()) { |
||
44 | $log(sprintf( |
||
45 | 'Data transfer (ID %s, Created: %s) is linked to a non-existent environment. Deleting', |
||
46 | $transfer->ID, |
||
47 | $transfer->Created |
||
48 | )); |
||
49 | $transfer->delete(); |
||
50 | $transfer->destroy(); |
||
51 | $count++; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | View Code Duplication | foreach (DNDataArchive::get() as $archive) { |
|
56 | $environment = $archive->Environment(); |
||
57 | if (!$environment || !$environment->exists()) { |
||
58 | $log(sprintf( |
||
59 | 'Archive (ID %s, Created: %s) is linked to a non-existent environment. Deleting', |
||
60 | $archive->ID, |
||
61 | $archive->Created |
||
62 | )); |
||
63 | $archive->delete(); |
||
64 | $archive->destroy(); |
||
65 | $count++; |
||
66 | } |
||
67 | } |
||
68 | |||
69 | View Code Duplication | foreach (DNGitFetch::get() as $fetch) { |
|
70 | $project = $fetch->Project(); |
||
71 | if (!$project || !$project->exists()) { |
||
72 | $log(sprintf( |
||
73 | 'Git fetch (ID %s, Created: %s) is linked to a non-existent project. Deleting', |
||
74 | $fetch->ID, |
||
75 | $fetch->Created |
||
76 | )); |
||
77 | $fetch->delete(); |
||
78 | $fetch->destroy(); |
||
79 | $count++; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | View Code Duplication | foreach (DNPing::get() as $ping) { |
|
84 | $environment = $ping->Environment(); |
||
85 | if (!$environment || !$environment->exists()) { |
||
86 | $log(sprintf( |
||
87 | 'Ping (ID %s, Created: %s) is linked to a non-existent environment. Deleting', |
||
88 | $ping->ID, |
||
89 | $ping->Created |
||
90 | )); |
||
91 | $ping->delete(); |
||
92 | $ping->destroy(); |
||
93 | $count++; |
||
94 | } |
||
95 | } |
||
96 | |||
97 | $log(sprintf('Finished. Processed %s records', $count)); |
||
98 | } |
||
99 | |||
101 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.