Completed
Pull Request — master (#6779)
by Blizzz
12:08
created
apps/comments/lib/Collaboration/CommentersSorter.php 2 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -29,76 +29,76 @@
 block discarded – undo
29 29
 
30 30
 class CommentersSorter implements ISorter {
31 31
 
32
-	/** @var ICommentsManager */
33
-	private $commentsManager;
34
-
35
-	public function __construct(ICommentsManager $commentsManager) {
36
-		$this->commentsManager = $commentsManager;
37
-	}
38
-
39
-	public function getId() {
40
-		return 'commenters';
41
-	}
42
-
43
-	/**
44
-	 * Sorts people who commented on the given item atop (descelating) of the
45
-	 * others
46
-	 *
47
-	 * @param array $sortArray
48
-	 * @param array $context
49
-	 */
50
-	public function sort(array &$sortArray, array $context) {
51
-		$commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']);
52
-		if(count($commenters) === 0) {
53
-			return;
54
-		}
55
-
56
-		foreach ($sortArray as $type => &$byType) {
57
-			if(!isset($commenters[$type])) {
58
-				continue;
59
-			}
60
-
61
-			// at least on PHP 5.6 usort turned out to be not stable. So we add
62
-			// the current index to the value and compare it on a draw
63
-			$i = 0;
64
-			$workArray = array_map(function($element) use (&$i) {
65
-				return [$i++, $element];
66
-			}, $byType);
67
-
68
-			usort($workArray, function ($a, $b) use ($commenters, $type) {
69
-				$r = $this->compare($a[1], $b[1], $commenters[$type]);
70
-				if($r === 0) {
71
-					$r = $a[0] - $b[0];
72
-				}
73
-				return $r;
74
-			});
75
-
76
-			// and remove the index values again
77
-			$byType = array_column($workArray, 1);
78
-		}
79
-	}
80
-
81
-	/**
82
-	 * @param $type
83
-	 * @param $id
84
-	 * @return array
85
-	 */
86
-	protected function retrieveCommentsInformation($type, $id) {
87
-		$comments = $this->commentsManager->getForObject($type, $id, 1);
88
-		if(count($comments) === 0) {
89
-			return [];
90
-		}
91
-
92
-		return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId());
93
-	}
94
-
95
-	protected function compare(array $a, array $b, array $commenters) {
96
-		$a = $a['value']['shareWith'];
97
-		$b = $b['value']['shareWith'];
98
-
99
-		$valueA = isset($commenters[$a]) ? $commenters[$a] : 0;
100
-		$valueB = isset($commenters[$b]) ? $commenters[$b] : 0;
101
-
102
-		return $valueB - $valueA;
103
-	}
32
+    /** @var ICommentsManager */
33
+    private $commentsManager;
34
+
35
+    public function __construct(ICommentsManager $commentsManager) {
36
+        $this->commentsManager = $commentsManager;
37
+    }
38
+
39
+    public function getId() {
40
+        return 'commenters';
41
+    }
42
+
43
+    /**
44
+     * Sorts people who commented on the given item atop (descelating) of the
45
+     * others
46
+     *
47
+     * @param array $sortArray
48
+     * @param array $context
49
+     */
50
+    public function sort(array &$sortArray, array $context) {
51
+        $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']);
52
+        if(count($commenters) === 0) {
53
+            return;
54
+        }
55
+
56
+        foreach ($sortArray as $type => &$byType) {
57
+            if(!isset($commenters[$type])) {
58
+                continue;
59
+            }
60
+
61
+            // at least on PHP 5.6 usort turned out to be not stable. So we add
62
+            // the current index to the value and compare it on a draw
63
+            $i = 0;
64
+            $workArray = array_map(function($element) use (&$i) {
65
+                return [$i++, $element];
66
+            }, $byType);
67
+
68
+            usort($workArray, function ($a, $b) use ($commenters, $type) {
69
+                $r = $this->compare($a[1], $b[1], $commenters[$type]);
70
+                if($r === 0) {
71
+                    $r = $a[0] - $b[0];
72
+                }
73
+                return $r;
74
+            });
75
+
76
+            // and remove the index values again
77
+            $byType = array_column($workArray, 1);
78
+        }
79
+    }
80
+
81
+    /**
82
+     * @param $type
83
+     * @param $id
84
+     * @return array
85
+     */
86
+    protected function retrieveCommentsInformation($type, $id) {
87
+        $comments = $this->commentsManager->getForObject($type, $id, 1);
88
+        if(count($comments) === 0) {
89
+            return [];
90
+        }
91
+
92
+        return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId());
93
+    }
94
+
95
+    protected function compare(array $a, array $b, array $commenters) {
96
+        $a = $a['value']['shareWith'];
97
+        $b = $b['value']['shareWith'];
98
+
99
+        $valueA = isset($commenters[$a]) ? $commenters[$a] : 0;
100
+        $valueB = isset($commenters[$b]) ? $commenters[$b] : 0;
101
+
102
+        return $valueB - $valueA;
103
+    }
104 104
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public function sort(array &$sortArray, array $context) {
51 51
 		$commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']);
52
-		if(count($commenters) === 0) {
52
+		if (count($commenters) === 0) {
53 53
 			return;
54 54
 		}
55 55
 
56 56
 		foreach ($sortArray as $type => &$byType) {
57
-			if(!isset($commenters[$type])) {
57
+			if (!isset($commenters[$type])) {
58 58
 				continue;
59 59
 			}
60 60
 
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 				return [$i++, $element];
66 66
 			}, $byType);
67 67
 
68
-			usort($workArray, function ($a, $b) use ($commenters, $type) {
68
+			usort($workArray, function($a, $b) use ($commenters, $type) {
69 69
 				$r = $this->compare($a[1], $b[1], $commenters[$type]);
70
-				if($r === 0) {
70
+				if ($r === 0) {
71 71
 					$r = $a[0] - $b[0];
72 72
 				}
73 73
 				return $r;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	protected function retrieveCommentsInformation($type, $id) {
87 87
 		$comments = $this->commentsManager->getForObject($type, $id, 1);
88
-		if(count($comments) === 0) {
88
+		if (count($comments) === 0) {
89 89
 			return [];
90 90
 		}
91 91
 
Please login to merge, or discard this patch.
apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -31,70 +31,70 @@
 block discarded – undo
31 31
 
32 32
 class ShareRecipientSorter implements ISorter {
33 33
 
34
-	/** @var IManager */
35
-	private $shareManager;
36
-	/** @var Folder */
37
-	private $userFolder;
34
+    /** @var IManager */
35
+    private $shareManager;
36
+    /** @var Folder */
37
+    private $userFolder;
38 38
 
39
-	public function __construct(IManager $shareManager, Folder $userFolder) {
40
-		$this->shareManager = $shareManager;
41
-		$this->userFolder = $userFolder;
42
-	}
39
+    public function __construct(IManager $shareManager, Folder $userFolder) {
40
+        $this->shareManager = $shareManager;
41
+        $this->userFolder = $userFolder;
42
+    }
43 43
 
44
-	public function getId() {
45
-		return 'share-recipients';
46
-	}
44
+    public function getId() {
45
+        return 'share-recipients';
46
+    }
47 47
 
48
-	public function sort(array &$sortArray, array $context) {
49
-		// let's be tolerant. Comments  uses "files" by default, other usages are often singular
50
-		if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') {
51
-			return;
52
-		}
53
-		/** @var Node[] $nodes */
54
-		$nodes = $this->userFolder->getById((int)$context['itemId']);
55
-		if(count($nodes) === 0) {
56
-			return;
57
-		}
58
-		$al = $this->shareManager->getAccessList($nodes[0]);
48
+    public function sort(array &$sortArray, array $context) {
49
+        // let's be tolerant. Comments  uses "files" by default, other usages are often singular
50
+        if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') {
51
+            return;
52
+        }
53
+        /** @var Node[] $nodes */
54
+        $nodes = $this->userFolder->getById((int)$context['itemId']);
55
+        if(count($nodes) === 0) {
56
+            return;
57
+        }
58
+        $al = $this->shareManager->getAccessList($nodes[0]);
59 59
 
60
-		foreach ($sortArray as $type => &$byType) {
61
-			if(!isset($al[$type]) || !is_array($al[$type])) {
62
-				continue;
63
-			}
60
+        foreach ($sortArray as $type => &$byType) {
61
+            if(!isset($al[$type]) || !is_array($al[$type])) {
62
+                continue;
63
+            }
64 64
 
65
-			// at least on PHP 5.6 usort turned out to be not stable. So we add
66
-			// the current index to the value and compare it on a draw
67
-			$i = 0;
68
-			$workArray = array_map(function($element) use (&$i) {
69
-				return [$i++, $element];
70
-			}, $byType);
65
+            // at least on PHP 5.6 usort turned out to be not stable. So we add
66
+            // the current index to the value and compare it on a draw
67
+            $i = 0;
68
+            $workArray = array_map(function($element) use (&$i) {
69
+                return [$i++, $element];
70
+            }, $byType);
71 71
 
72
-			usort($workArray, function ($a, $b) use ($al, $type) {
73
-				$result = $this->compare($a[1], $b[1], $al[$type]);
74
-				if($result === 0) {
75
-					$result = $a[0] - $b[0];
76
-				}
77
-				return $result;
78
-			});
72
+            usort($workArray, function ($a, $b) use ($al, $type) {
73
+                $result = $this->compare($a[1], $b[1], $al[$type]);
74
+                if($result === 0) {
75
+                    $result = $a[0] - $b[0];
76
+                }
77
+                return $result;
78
+            });
79 79
 
80
-			// and remove the index values again
81
-			$byType = array_column($workArray, 1);
82
-		}
83
-	}
80
+            // and remove the index values again
81
+            $byType = array_column($workArray, 1);
82
+        }
83
+    }
84 84
 
85
-	/**
86
-	 * @param array $a
87
-	 * @param array $b
88
-	 * @param array $al
89
-	 * @return int
90
-	 */
91
-	protected function compare(array $a, array $b, array $al) {
92
-		$a = $a['value']['shareWith'];
93
-		$b = $b['value']['shareWith'];
85
+    /**
86
+     * @param array $a
87
+     * @param array $b
88
+     * @param array $al
89
+     * @return int
90
+     */
91
+    protected function compare(array $a, array $b, array $al) {
92
+        $a = $a['value']['shareWith'];
93
+        $b = $b['value']['shareWith'];
94 94
 
95
-		$valueA = (int)in_array($a, $al, true);
96
-		$valueB = (int)in_array($b, $al, true);
95
+        $valueA = (int)in_array($a, $al, true);
96
+        $valueB = (int)in_array($b, $al, true);
97 97
 
98
-		return $valueB - $valueA;
99
-	}
98
+        return $valueB - $valueA;
99
+    }
100 100
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
 
48 48
 	public function sort(array &$sortArray, array $context) {
49 49
 		// let's be tolerant. Comments  uses "files" by default, other usages are often singular
50
-		if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') {
50
+		if ($context['itemType'] !== 'files' && $context['itemType'] !== 'file') {
51 51
 			return;
52 52
 		}
53 53
 		/** @var Node[] $nodes */
54
-		$nodes = $this->userFolder->getById((int)$context['itemId']);
55
-		if(count($nodes) === 0) {
54
+		$nodes = $this->userFolder->getById((int) $context['itemId']);
55
+		if (count($nodes) === 0) {
56 56
 			return;
57 57
 		}
58 58
 		$al = $this->shareManager->getAccessList($nodes[0]);
59 59
 
60 60
 		foreach ($sortArray as $type => &$byType) {
61
-			if(!isset($al[$type]) || !is_array($al[$type])) {
61
+			if (!isset($al[$type]) || !is_array($al[$type])) {
62 62
 				continue;
63 63
 			}
64 64
 
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 				return [$i++, $element];
70 70
 			}, $byType);
71 71
 
72
-			usort($workArray, function ($a, $b) use ($al, $type) {
72
+			usort($workArray, function($a, $b) use ($al, $type) {
73 73
 				$result = $this->compare($a[1], $b[1], $al[$type]);
74
-				if($result === 0) {
74
+				if ($result === 0) {
75 75
 					$result = $a[0] - $b[0];
76 76
 				}
77 77
 				return $result;
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 		$a = $a['value']['shareWith'];
93 93
 		$b = $b['value']['shareWith'];
94 94
 
95
-		$valueA = (int)in_array($a, $al, true);
96
-		$valueB = (int)in_array($b, $al, true);
95
+		$valueA = (int) in_array($a, $al, true);
96
+		$valueB = (int) in_array($b, $al, true);
97 97
 
98 98
 		return $valueB - $valueA;
99 99
 	}
Please login to merge, or discard this patch.