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