Completed
Pull Request — master (#713)
by Sean
04:10
created

CleanupOrphanedRecordsTask   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 98
Duplicated Lines 83.67 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 19
lcom 0
cbo 7
dl 82
loc 98
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
F run() 82 94 19

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class CleanupOrphanedRecordsTask extends BuildTask {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
5
	public function run($request) {
6 View Code Duplication
		$log = function($message) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
100
}
101