Passed
Push — master ( 97f2c5...5b43af )
by Roeland
12:54 queued 11s
created
core/Controller/AutoCompleteController.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -40,88 +40,88 @@
 block discarded – undo
40 40
 use OCP\Share\IShare;
41 41
 
42 42
 class AutoCompleteController extends Controller {
43
-	/** @var ISearch */
44
-	private $collaboratorSearch;
45
-
46
-	/** @var IManager */
47
-	private $autoCompleteManager;
48
-
49
-	/** @var IEventDispatcher */
50
-	private $dispatcher;
51
-
52
-	public function __construct(string $appName,
53
-								IRequest $request,
54
-								ISearch $collaboratorSearch,
55
-								IManager $autoCompleteManager,
56
-								IEventDispatcher $dispatcher) {
57
-		parent::__construct($appName, $request);
58
-
59
-		$this->collaboratorSearch = $collaboratorSearch;
60
-		$this->autoCompleteManager = $autoCompleteManager;
61
-		$this->dispatcher = $dispatcher;
62
-	}
63
-
64
-	/**
65
-	 * @NoAdminRequired
66
-	 *
67
-	 * @param string $search
68
-	 * @param string $itemType
69
-	 * @param string $itemId
70
-	 * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients"
71
-	 * @param array $shareTypes
72
-	 * @param int $limit
73
-	 * @return DataResponse
74
-	 */
75
-	public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [IShare::TYPE_USER], $limit = 10): DataResponse {
76
-		// if enumeration/user listings are disabled, we'll receive an empty
77
-		// result from search() – thus nothing else to do here.
78
-		[$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0);
79
-
80
-		$event = new AutoCompleteEvent([
81
-			'search' => $search,
82
-			'results' => $results,
83
-			'itemType' => $itemType,
84
-			'itemId' => $itemId,
85
-			'sorter' => $sorter,
86
-			'shareTypes' => $shareTypes,
87
-			'limit' => $limit,
88
-		]);
89
-		$this->dispatcher->dispatch(IManager::class . '::filterResults', $event);
90
-		$results = $event->getResults();
91
-
92
-		$exactMatches = $results['exact'];
93
-		unset($results['exact']);
94
-		$results = array_merge_recursive($exactMatches, $results);
95
-
96
-		if ($sorter !== null) {
97
-			$sorters = array_reverse(explode('|', $sorter));
98
-			$this->autoCompleteManager->runSorters($sorters, $results, [
99
-				'itemType' => $itemType,
100
-				'itemId' => $itemId,
101
-			]);
102
-		}
103
-
104
-		// transform to expected format
105
-		$results = $this->prepareResultArray($results);
106
-
107
-		return new DataResponse($results);
108
-	}
109
-
110
-
111
-	protected function prepareResultArray(array $results): array {
112
-		$output = [];
113
-		foreach ($results as $type => $subResult) {
114
-			foreach ($subResult as $result) {
115
-				$output[] = [
116
-					'id' => (string) $result['value']['shareWith'],
117
-					'label' => $result['label'],
118
-					'icon' => $result['icon'] ?? '',
119
-					'source' => $type,
120
-					'status' => $result['status'] ?? '',
121
-					'subline' => $result['subline'] ?? '',
122
-				];
123
-			}
124
-		}
125
-		return $output;
126
-	}
43
+    /** @var ISearch */
44
+    private $collaboratorSearch;
45
+
46
+    /** @var IManager */
47
+    private $autoCompleteManager;
48
+
49
+    /** @var IEventDispatcher */
50
+    private $dispatcher;
51
+
52
+    public function __construct(string $appName,
53
+                                IRequest $request,
54
+                                ISearch $collaboratorSearch,
55
+                                IManager $autoCompleteManager,
56
+                                IEventDispatcher $dispatcher) {
57
+        parent::__construct($appName, $request);
58
+
59
+        $this->collaboratorSearch = $collaboratorSearch;
60
+        $this->autoCompleteManager = $autoCompleteManager;
61
+        $this->dispatcher = $dispatcher;
62
+    }
63
+
64
+    /**
65
+     * @NoAdminRequired
66
+     *
67
+     * @param string $search
68
+     * @param string $itemType
69
+     * @param string $itemId
70
+     * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients"
71
+     * @param array $shareTypes
72
+     * @param int $limit
73
+     * @return DataResponse
74
+     */
75
+    public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [IShare::TYPE_USER], $limit = 10): DataResponse {
76
+        // if enumeration/user listings are disabled, we'll receive an empty
77
+        // result from search() – thus nothing else to do here.
78
+        [$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0);
79
+
80
+        $event = new AutoCompleteEvent([
81
+            'search' => $search,
82
+            'results' => $results,
83
+            'itemType' => $itemType,
84
+            'itemId' => $itemId,
85
+            'sorter' => $sorter,
86
+            'shareTypes' => $shareTypes,
87
+            'limit' => $limit,
88
+        ]);
89
+        $this->dispatcher->dispatch(IManager::class . '::filterResults', $event);
90
+        $results = $event->getResults();
91
+
92
+        $exactMatches = $results['exact'];
93
+        unset($results['exact']);
94
+        $results = array_merge_recursive($exactMatches, $results);
95
+
96
+        if ($sorter !== null) {
97
+            $sorters = array_reverse(explode('|', $sorter));
98
+            $this->autoCompleteManager->runSorters($sorters, $results, [
99
+                'itemType' => $itemType,
100
+                'itemId' => $itemId,
101
+            ]);
102
+        }
103
+
104
+        // transform to expected format
105
+        $results = $this->prepareResultArray($results);
106
+
107
+        return new DataResponse($results);
108
+    }
109
+
110
+
111
+    protected function prepareResultArray(array $results): array {
112
+        $output = [];
113
+        foreach ($results as $type => $subResult) {
114
+            foreach ($subResult as $result) {
115
+                $output[] = [
116
+                    'id' => (string) $result['value']['shareWith'],
117
+                    'label' => $result['label'],
118
+                    'icon' => $result['icon'] ?? '',
119
+                    'source' => $type,
120
+                    'status' => $result['status'] ?? '',
121
+                    'subline' => $result['subline'] ?? '',
122
+                ];
123
+            }
124
+        }
125
+        return $output;
126
+    }
127 127
 }
Please login to merge, or discard this patch.