Completed
Pull Request — master (#388)
by
unknown
02:39
created
lib-vendor-organizer.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@  discard block
 block discarded – undo
2 2
 <?php
3 3
 
4 4
 $sourceDirectory = $argv[1];
5
-$sourceDirectory = rtrim($sourceDirectory, '/') . '/';
5
+$sourceDirectory = rtrim($sourceDirectory, '/').'/';
6 6
 
7 7
 if (!str_starts_with('/', $sourceDirectory)) {
8
-	$sourceDirectory = getcwd() . '/' . $sourceDirectory;
8
+	$sourceDirectory = getcwd().'/'.$sourceDirectory;
9 9
 }
10 10
 
11 11
 $stripNamespacePrefix = $argv[2] ?? '';
@@ -18,39 +18,39 @@  discard block
 block discarded – undo
18 18
 	exit(1);
19 19
 }
20 20
 $organizationList = [];
21
-foreach(scandir($sourceDirectory) as $file) {
22
-	if (!is_dir($sourceDirectory . $file) || $file === '.' || $file === '..') {
21
+foreach (scandir($sourceDirectory) as $file) {
22
+	if (!is_dir($sourceDirectory.$file) || $file === '.' || $file === '..') {
23 23
 		continue;
24 24
 	}
25
-	$organizationList[] = $sourceDirectory . $file . '/';
25
+	$organizationList[] = $sourceDirectory.$file.'/';
26 26
 }
27 27
 
28 28
 $projectList = [];
29
-foreach($organizationList as $organizationDir) {
30
-	foreach(scandir($organizationDir) as $file) {
31
-		if (!is_dir($organizationDir . $file) || $file === '.' || $file === '..') {
29
+foreach ($organizationList as $organizationDir) {
30
+	foreach (scandir($organizationDir) as $file) {
31
+		if (!is_dir($organizationDir.$file) || $file === '.' || $file === '..') {
32 32
 			continue;
33 33
 		}
34
-		$projectList[] = $organizationDir . $file . '/';
34
+		$projectList[] = $organizationDir.$file.'/';
35 35
 	}
36 36
 }
37 37
 
38 38
 $destinations = array();
39 39
 foreach ($projectList as $projectDir) {
40
-	if (!file_exists($projectDir . 'composer.json')) {
40
+	if (!file_exists($projectDir.'composer.json')) {
41 41
 		continue;
42 42
 	}
43 43
 
44
-	$projectInfo = json_decode(file_get_contents($projectDir . 'composer.json'), true);
44
+	$projectInfo = json_decode(file_get_contents($projectDir.'composer.json'), true);
45 45
     if (!isset($projectInfo['autoload']['psr-4'])) {
46
-		printf("No supported autoload configuration in %s" . PHP_EOL, $projectDir);
46
+		printf("No supported autoload configuration in %s".PHP_EOL, $projectDir);
47 47
 		exit(2);
48 48
 	}
49 49
 	foreach ($projectInfo['autoload']['psr-4'] as $namespace => $codeDir) {
50 50
 		if ($stripNamespacePrefix !== '' && str_starts_with($namespace, $stripNamespacePrefix)) {
51 51
 			$namespace = str_replace($stripNamespacePrefix, '', $namespace);
52 52
 		}
53
-		$destination = rtrim($sourceDirectory, '/') . str_replace('\\', '/', $namespace);
53
+		$destination = rtrim($sourceDirectory, '/').str_replace('\\', '/', $namespace);
54 54
         $destinations = insertion_sort($destinations, [
55 55
                 "destination"=>$destination,
56 56
                 "codeDir"=>$codeDir,
@@ -69,20 +69,20 @@  discard block
 block discarded – undo
69 69
     }
70 70
     mkdir($destination, 0777, true);
71 71
 
72
-    if (!rename_or_move($projectDir . $codeDir, $destination)) {
73
-        printf("Failed to move %s to %s" . PHP_EOL, $projectDir . $codeDir, $destination);
72
+    if (!rename_or_move($projectDir.$codeDir, $destination)) {
73
+        printf("Failed to move %s to %s".PHP_EOL, $projectDir.$codeDir, $destination);
74 74
         exit(3);
75 75
     }
76 76
 }
77 77
 
78 78
 function insertion_sort($array, $element): array
79 79
 {
80
-    for($i = 0; $i < count($array); $i++) {
80
+    for ($i = 0; $i < count($array); $i++) {
81 81
         $compare = strcmp($array[$i]["destination"], $element["destination"]);
82
-        if($compare > 0) {
82
+        if ($compare > 0) {
83 83
             array_splice($array, $i, 0, [$element]);
84 84
             return $array;
85
-        }else if($compare == 0){
85
+        } else if ($compare == 0) {
86 86
             return $array;
87 87
         }
88 88
     }
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
     return $array;
91 91
 }
92 92
 
93
-foreach($organizationList as $organizationDir) {
93
+foreach ($organizationList as $organizationDir) {
94 94
 	rmdir_recursive($organizationDir);
95 95
 }
96 96
 
97 97
 function rmdir_recursive($dir): void
98 98
 {
99
-	foreach(scandir($dir) as $file) {
99
+	foreach (scandir($dir) as $file) {
100 100
 		if ('.' === $file || '..' === $file) {
101 101
 			continue;
102 102
 		}
Please login to merge, or discard this patch.