1111use OCA \Tables \Model \Permissions ;
1212use OCA \Tables \Model \SortRuleSet ;
1313use OCA \Tables \ResponseDefinitions ;
14- use OCA \Tables \Service \ValueObject \ViewColumnInformation ;
14+ use OCA \Tables \Service \ValueObject \ColumnOrderInformation ;
1515
1616/**
1717 * @psalm-suppress PropertyNotSetInConstructor
4444 * @method setRowsCount(int $rowsCount)
4545 * @method getColumnsCount(): int
4646 * @method setColumnsCount(int $columnsCount)
47- * @method getViews(): ?array
47+ * @method getViews(): ?array<TablesView>
4848 * @method setViews(array $views)
4949 * @method getColumns(): array
5050 * @method setColumns(array $columns)
@@ -109,14 +109,17 @@ public function jsonSerialize(): array {
109109 'lastEditAt ' => $ this ->lastEditAt ?: '' ,
110110 'archived ' => $ this ->archived ,
111111 'isShared ' => (bool )$ this ->isShared ,
112- 'favorite ' => $ this ->favorite ,
112+ 'favorite ' => ( bool ) $ this ->favorite ,
113113 'onSharePermissions ' => $ this ->getSharePermissions ()?->jsonSerialize(),
114114 'hasShares ' => (bool )$ this ->hasShares ,
115115 'rowsCount ' => $ this ->rowsCount ?: 0 ,
116116 'columnsCount ' => $ this ->columnsCount ?: 0 ,
117- 'views ' => $ this ->getViewsArray (),
118- 'description ' => $ this ->description ?:'' ,
119- 'columnOrder ' => $ this ->getColumnOrderSettingsArray (),
117+ 'description ' => $ this ->description ?: '' ,
118+ 'views ' => array_values ($ this ->getViewsArray ()),
119+ 'columnOrder ' => array_map (
120+ static fn (ColumnOrderInformation $ c ) => ['columnId ' => $ c ->getId (), 'order ' => $ c ->getOrder ()],
121+ $ this ->getColumnOrderSettingsArray ()
122+ ),
120123 'sort ' => $ this ->getSortArray (),
121124 ];
122125 }
@@ -126,27 +129,26 @@ private function getSharePermissions(): ?Permissions {
126129 }
127130
128131 /**
129- * @psalm-suppress MismatchingDocblockReturnType
130132 * @return TablesView[]
131133 */
132134 private function getViewsArray (): array {
133135 return $ this ->getViews () ?: [];
134136 }
135137
136138 /**
137- * @psalm-suppress MismatchingDocblockReturnType
138139 * @return int[]
139140 */
140141 public function getColumnOrderArray (): array {
141142 $ columnSettings = $ this ->getColumnOrderSettingsArray ();
142- usort ($ columnSettings , static function (ViewColumnInformation $ a , ViewColumnInformation $ b ) {
143+ usort ($ columnSettings , static function (ColumnOrderInformation $ a , ColumnOrderInformation $ b ) {
143144 return $ a ->getOrder () - $ b ->getOrder ();
144145 });
145- return array_map (static fn (ViewColumnInformation $ vci ): int => $ vci ->getId (), $ columnSettings );
146+ /** @var list<ColumnOrderInformation> $columnSettings */
147+ return array_map (static fn (ColumnOrderInformation $ vci ): int => $ vci ->getId (), $ columnSettings );
146148 }
147149
148150 /**
149- * @return array<ViewColumnInformation >
151+ * @return list<ColumnOrderInformation >
150152 */
151153 public function getColumnOrderSettingsArray (): array {
152154 $ columns = $ this ->getArray ($ this ->getColumnOrder ());
@@ -155,18 +157,17 @@ public function getColumnOrderSettingsArray(): array {
155157 }
156158
157159 if (is_array ($ columns [array_key_first ($ columns )] ?? null )) {
158- return array_values (array_map (static fn (array $ a ): ViewColumnInformation => ViewColumnInformation ::fromArray ($ a ), $ columns ));
160+ return array_values (array_map (static fn (array $ a ): ColumnOrderInformation => ColumnOrderInformation ::fromArray ($ a ), $ columns ));
159161 }
160162
161163 $ result = [];
162164 foreach ($ columns as $ index => $ columnId ) {
163- $ result [] = new ViewColumnInformation ( $ columnId , order: (int )$ index + 1 );
165+ $ result [] = new ColumnOrderInformation (( int ) $ columnId , order: (int )$ index + 1 );
164166 }
165167 return $ result ;
166168 }
167169
168170 /**
169- * @psalm-suppress MismatchingDocblockReturnType
170171 * @return list<array{columnId: int, mode: 'ASC'|'DESC'}>
171172 */
172173 public function getSortArray (): array {
@@ -176,9 +177,8 @@ public function getSortArray(): array {
176177
177178 private function getArray (?string $ json ): array {
178179 if ($ json !== '' && $ json !== null && $ json !== 'null ' ) {
179- return \json_decode ($ json , true );
180- } else {
181- return [];
180+ return \json_decode ($ json , true ) ?? [];
182181 }
182+ return [];
183183 }
184184}
0 commit comments